minor #40484 [DependencyInjection] accept null index in #[TaggedItem] (nicolas-grekas)

This PR was merged into the 5.3-dev branch.

Discussion
----------

[DependencyInjection] accept null index in #[TaggedItem]

| Q             | A
| ------------- | ---
| Branch?       | 5.x
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

As hinted by @stof in https://github.com/symfony/symfony/pull/40248#discussion_r595065941

Commits
-------

6d16fac703 [DI] accept null index in #[TaggedItem]
This commit is contained in:
Nicolas Grekas 2021-03-16 20:14:20 +01:00
commit 49d23d4813
2 changed files with 10 additions and 1 deletions

View File

@ -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,
) {
}

View File

@ -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
{
}