Skip to content

Commit 6051807

Browse files
[DI] accept null index in #[TaggedItem]
1 parent 7cc5cef commit 6051807

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 0 deletions
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
];
@@ -231,7 +235,13 @@ public function test($tagName, ContainerBuilder $container)
231235
}
232236
}
233237

238+
234239
#[TaggedItem(index: 'hello', priority: 1)]
235240
class HelloNamedService extends \stdClass
236241
{
237242
}
243+
244+
#[TaggedItem(priority: 2)]
245+
class HelloNamedService2
246+
{
247+
}

0 commit comments

Comments
 (0)