Skip to content

Commit 8d7e2e3

Browse files
[DI] accept null index in #[TaggedItem]
1 parent 0c78585 commit 8d7e2e3

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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
}

Tests/Compiler/PriorityTaggedServiceTraitTest.php

Lines changed: 9 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
];
@@ -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)