[DI] accept null index in #[TaggedItem]

This commit is contained in:
Nicolas Grekas 2021-03-16 12:16:39 +01:00
parent 7cc5cef1c3
commit 6d16fac703
2 changed files with 10 additions and 1 deletions

View File

@ -20,7 +20,7 @@ namespace Symfony\Component\DependencyInjection\Attribute;
class TaggedItem class TaggedItem
{ {
public function __construct( public function __construct(
public string $index, public ?string $index = null,
public ?int $priority = null, public ?int $priority = null,
) { ) {
} }

View File

@ -205,6 +205,9 @@ class PriorityTaggedServiceTraitTest extends TestCase
HelloNamedService::class => (new ChildDefinition(''))->addTag('my_custom_tag'), HelloNamedService::class => (new ChildDefinition(''))->addTag('my_custom_tag'),
\stdClass::class => (new ChildDefinition(''))->addTag('my_custom_tag2'), \stdClass::class => (new ChildDefinition(''))->addTag('my_custom_tag2'),
]); ]);
$container->register('service3', HelloNamedService2::class)
->setAutoconfigured(true)
->addTag('my_custom_tag');
(new ResolveInstanceofConditionalsPass())->process($container); (new ResolveInstanceofConditionalsPass())->process($container);
@ -212,6 +215,7 @@ class PriorityTaggedServiceTraitTest extends TestCase
$tag = new TaggedIteratorArgument('my_custom_tag', 'foo', 'getFooBar'); $tag = new TaggedIteratorArgument('my_custom_tag', 'foo', 'getFooBar');
$expected = [ $expected = [
'service3' => new TypedReference('service3', HelloNamedService2::class),
'hello' => new TypedReference('service2', HelloNamedService::class), 'hello' => new TypedReference('service2', HelloNamedService::class),
'service1' => new TypedReference('service1', FooTagClass::class), 'service1' => new TypedReference('service1', FooTagClass::class),
]; ];
@ -235,3 +239,8 @@ class PriorityTaggedServiceTraitImplementation
class HelloNamedService extends \stdClass class HelloNamedService extends \stdClass
{ {
} }
#[TaggedItem(priority: 2)]
class HelloNamedService2
{
}