diff --git a/src/Symfony/Component/DependencyInjection/Loader/Configurator/AbstractConfigurator.php b/src/Symfony/Component/DependencyInjection/Loader/Configurator/AbstractConfigurator.php index 6de2d67641c7..8cf44ca38916 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/Configurator/AbstractConfigurator.php +++ b/src/Symfony/Component/DependencyInjection/Loader/Configurator/AbstractConfigurator.php @@ -101,6 +101,7 @@ public static function processValue($value, $allowServices = false) switch (true) { case null === $value: case \is_scalar($value): + case $value instanceof \UnitEnum: return $value; case $value instanceof ArgumentInterface: diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/services_with_enumeration.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/services_with_enumeration.php new file mode 100644 index 000000000000..2261f3973213 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/services_with_enumeration.php @@ -0,0 +1,23 @@ +parameters() + ->set('unit_enum', FooUnitEnum::BAR) + ->set('enum_array', [FooUnitEnum::BAR, FooUnitEnum::FOO]); + + $services = $container->services(); + + $services->defaults()->public(); + + $services->set('service_container', ContainerInterface::class) + ->synthetic(); + + $services->set(FooClassWithEnumAttribute::class) + ->args([FooUnitEnum::BAR]); +}; diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php index 8b141d2577ee..6423332fa517 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/PhpFileLoaderTest.php @@ -22,6 +22,8 @@ use Symfony\Component\DependencyInjection\Dumper\YamlDumper; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; +use Symfony\Component\DependencyInjection\Tests\Fixtures\FooClassWithEnumAttribute; +use Symfony\Component\DependencyInjection\Tests\Fixtures\FooUnitEnum; class PhpFileLoaderTest extends TestCase { @@ -165,6 +167,22 @@ public function testEnvConfigurator() $this->assertSame('%env(int:CCC)%', $container->getDefinition('foo')->getArgument(0)); } + /** + * @requires PHP 8.1 + */ + public function testEnumeration() + { + $fixtures = realpath(__DIR__.'/../Fixtures'); + $container = new ContainerBuilder(); + $loader = new PhpFileLoader($container, new FileLocator($fixtures.'/config')); + $loader->load('services_with_enumeration.php'); + + $container->compile(); + + $definition = $container->getDefinition(FooClassWithEnumAttribute::class); + $this->assertSame([FooUnitEnum::BAR], $definition->getArguments()); + } + /** * @group legacy */
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: