Skip to content

Commit

Permalink
minor #40484 [DependencyInjection] accept null index in #[TaggedItem]…
Browse files Browse the repository at this point in the history
… (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 #40248 (comment)

Commits
-------

6d16fac [DI] accept null index in #[TaggedItem]
  • Loading branch information
nicolas-grekas committed Mar 16, 2021
2 parents db87d72 + 6d16fac commit 49d23d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class TaggedItem
{
public function __construct(
public string $index,
public ?string $index = null,
public ?int $priority = null,
) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,17 @@ 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);

$priorityTaggedServiceTraitImplementation = new PriorityTaggedServiceTraitImplementation();

$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),
];
Expand All @@ -235,3 +239,8 @@ public function test($tagName, ContainerBuilder $container)
class HelloNamedService extends \stdClass
{
}

#[TaggedItem(priority: 2)]
class HelloNamedService2
{
}

0 comments on commit 49d23d4

Please sign in to comment.