[DI] accept null index in #[TaggedItem]
This commit is contained in:
parent
7cc5cef1c3
commit
6d16fac703
@ -20,7 +20,7 @@ namespace Symfony\Component\DependencyInjection\Attribute;
|
|||||||
class TaggedItem
|
class TaggedItem
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
public string $index,
|
public ?string $index = null,
|
||||||
public ?int $priority = null,
|
public ?int $priority = null,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
@ -205,6 +205,9 @@ class PriorityTaggedServiceTraitTest extends TestCase
|
|||||||
HelloNamedService::class => (new ChildDefinition(''))->addTag('my_custom_tag'),
|
HelloNamedService::class => (new ChildDefinition(''))->addTag('my_custom_tag'),
|
||||||
\stdClass::class => (new ChildDefinition(''))->addTag('my_custom_tag2'),
|
\stdClass::class => (new ChildDefinition(''))->addTag('my_custom_tag2'),
|
||||||
]);
|
]);
|
||||||
|
$container->register('service3', HelloNamedService2::class)
|
||||||
|
->setAutoconfigured(true)
|
||||||
|
->addTag('my_custom_tag');
|
||||||
|
|
||||||
(new ResolveInstanceofConditionalsPass())->process($container);
|
(new ResolveInstanceofConditionalsPass())->process($container);
|
||||||
|
|
||||||
@ -212,6 +215,7 @@ class PriorityTaggedServiceTraitTest extends TestCase
|
|||||||
|
|
||||||
$tag = new TaggedIteratorArgument('my_custom_tag', 'foo', 'getFooBar');
|
$tag = new TaggedIteratorArgument('my_custom_tag', 'foo', 'getFooBar');
|
||||||
$expected = [
|
$expected = [
|
||||||
|
'service3' => new TypedReference('service3', HelloNamedService2::class),
|
||||||
'hello' => new TypedReference('service2', HelloNamedService::class),
|
'hello' => new TypedReference('service2', HelloNamedService::class),
|
||||||
'service1' => new TypedReference('service1', FooTagClass::class),
|
'service1' => new TypedReference('service1', FooTagClass::class),
|
||||||
];
|
];
|
||||||
@ -235,3 +239,8 @@ class PriorityTaggedServiceTraitImplementation
|
|||||||
class HelloNamedService extends \stdClass
|
class HelloNamedService extends \stdClass
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[TaggedItem(priority: 2)]
|
||||||
|
class HelloNamedService2
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user