Autoconfig: don't automatically tag decorators
This commit is contained in:
parent
7535383163
commit
05ecf829fe
@ -113,14 +113,17 @@ class ResolveInstanceofConditionalsPass implements CompilerPassInterface
|
||||
$definition->setShared($shared);
|
||||
}
|
||||
|
||||
$i = \count($instanceofTags);
|
||||
while (0 <= --$i) {
|
||||
foreach ($instanceofTags[$i] as $k => $v) {
|
||||
foreach ($v as $v) {
|
||||
if ($definition->hasTag($k) && \in_array($v, $definition->getTag($k))) {
|
||||
continue;
|
||||
// Don't add tags to service decorators
|
||||
if (null === $definition->getDecoratedService()) {
|
||||
$i = \count($instanceofTags);
|
||||
while (0 <= --$i) {
|
||||
foreach ($instanceofTags[$i] as $k => $v) {
|
||||
foreach ($v as $v) {
|
||||
if ($definition->hasTag($k) && \in_array($v, $definition->getTag($k))) {
|
||||
continue;
|
||||
}
|
||||
$definition->addTag($k, $v);
|
||||
}
|
||||
$definition->addTag($k, $v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -307,4 +307,26 @@ class ResolveInstanceofConditionalsPassTest extends TestCase
|
||||
$this->assertInstanceOf(BoundArgument::class, $bindings['$toto']);
|
||||
$this->assertSame(123, $bindings['$toto']->getValues()[0]);
|
||||
}
|
||||
|
||||
public function testDecoratorsAreNotAutomaticallyTagged()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$decorator = $container->register('decorator', self::class);
|
||||
$decorator->setDecoratedService('decorated');
|
||||
$decorator->setInstanceofConditionals([
|
||||
parent::class => (new ChildDefinition(''))->addTag('tag'),
|
||||
]);
|
||||
$decorator->setAutoconfigured(true);
|
||||
$decorator->addTag('manual');
|
||||
|
||||
$container->registerForAutoconfiguration(parent::class)
|
||||
->addTag('tag')
|
||||
;
|
||||
|
||||
(new ResolveInstanceofConditionalsPass())->process($container);
|
||||
(new ResolveChildDefinitionsPass())->process($container);
|
||||
|
||||
$this->assertSame(['manual' => [[]]], $container->getDefinition('decorator')->getTags());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user