diff --git a/src/Symfony/Component/DependencyInjection/Attribute/TaggedItem.php b/src/Symfony/Component/DependencyInjection/Attribute/TaggedItem.php index b7ba825ae8e5f..a848e68d63516 100644 --- a/src/Symfony/Component/DependencyInjection/Attribute/TaggedItem.php +++ b/src/Symfony/Component/DependencyInjection/Attribute/TaggedItem.php @@ -20,7 +20,7 @@ class TaggedItem { public function __construct( - public string $index, + public ?string $index = null, public ?int $priority = null, ) { } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php index 1ef1521b7d86c..bd3b82d64f74a 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php @@ -205,6 +205,9 @@ public function testTaggedItemAttributes() HelloNamedService::class => (new ChildDefinition(''))->addTag('my_custom_tag'), \stdClass::class => (new ChildDefinition(''))->addTag('my_custom_tag2'), ]); + $container->register('service3', HelloNamedService2::class) + ->setAutoconfigured(true) + ->addTag('my_custom_tag'); (new ResolveInstanceofConditionalsPass())->process($container); @@ -212,6 +215,7 @@ public function testTaggedItemAttributes() $tag = new TaggedIteratorArgument('my_custom_tag', 'foo', 'getFooBar'); $expected = [ + 'service3' => new TypedReference('service3', HelloNamedService2::class), 'hello' => new TypedReference('service2', HelloNamedService::class), 'service1' => new TypedReference('service1', FooTagClass::class), ]; @@ -235,3 +239,8 @@ public function test($tagName, ContainerBuilder $container) class HelloNamedService extends \stdClass { } + +#[TaggedItem(priority: 2)] +class HelloNamedService2 +{ +}