Skip to content

Commit 49d23d4

Browse files
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 #40248 (comment) Commits ------- 6d16fac [DI] accept null index in #[TaggedItem]
2 parents db87d72 + 6d16fac commit 49d23d4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Symfony/Component/DependencyInjection/Attribute/TaggedItem.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class TaggedItem
2121
{
2222
public function __construct(
23-
public string $index,
23+
public ?string $index = null,
2424
public ?int $priority = null,
2525
) {
2626
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/PriorityTaggedServiceTraitTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,17 @@ public function testTaggedItemAttributes()
205205
HelloNamedService::class => (new ChildDefinition(''))->addTag('my_custom_tag'),
206206
\stdClass::class => (new ChildDefinition(''))->addTag('my_custom_tag2'),
207207
]);
208+
$container->register('service3', HelloNamedService2::class)
209+
->setAutoconfigured(true)
210+
->addTag('my_custom_tag');
208211

209212
(new ResolveInstanceofConditionalsPass())->process($container);
210213

211214
$priorityTaggedServiceTraitImplementation = new PriorityTaggedServiceTraitImplementation();
212215

213216
$tag = new TaggedIteratorArgument('my_custom_tag', 'foo', 'getFooBar');
214217
$expected = [
218+
'service3' => new TypedReference('service3', HelloNamedService2::class),
215219
'hello' => new TypedReference('service2', HelloNamedService::class),
216220
'service1' => new TypedReference('service1', FooTagClass::class),
217221
];
@@ -235,3 +239,8 @@ public function test($tagName, ContainerBuilder $container)
235239
class HelloNamedService extends \stdClass
236240
{
237241
}
242+
243+
#[TaggedItem(priority: 2)]
244+
class HelloNamedService2
245+
{
246+
}

0 commit comments

Comments
 (0)