From 6d16fac703d4787a876516af02f923d6c98b7a6b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 16 Mar 2021 12:16:39 +0100 Subject: [PATCH] [DI] accept null index in #[TaggedItem] --- .../DependencyInjection/Attribute/TaggedItem.php | 2 +- .../Tests/Compiler/PriorityTaggedServiceTraitTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/DependencyInjection/Attribute/TaggedItem.php b/src/Symfony/Component/DependencyInjection/Attribute/TaggedItem.php index b7ba825ae8..a848e68d63 100644 --- a/src/Symfony/Component/DependencyInjection/Attribute/TaggedItem.php +++ b/src/Symfony/Component/DependencyInjection/Attribute/TaggedItem.php @@ -20,7 +20,7 @@ namespace Symfony\Component\DependencyInjection\Attribute; 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 1ef1521b7d..bd3b82d64f 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php @@ -205,6 +205,9 @@ class PriorityTaggedServiceTraitTest extends TestCase 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 @@ class PriorityTaggedServiceTraitTest extends TestCase $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 @@ class PriorityTaggedServiceTraitImplementation class HelloNamedService extends \stdClass { } + +#[TaggedItem(priority: 2)] +class HelloNamedService2 +{ +}