[DependencyInjection] Fix tags on multiple decorated service
This commit is contained in:
parent
80670fc0a7
commit
90f8df2830
@ -34,6 +34,7 @@ class DecoratorServicePass implements CompilerPassInterface
|
||||
}
|
||||
$definitions->insert(array($id, $definition), array($decorated[2], --$order));
|
||||
}
|
||||
$decoratingDefinitions = array();
|
||||
|
||||
foreach ($definitions as list($id, $definition)) {
|
||||
list($inner, $renamedId) = $definition->getDecoratedService();
|
||||
@ -53,18 +54,25 @@ class DecoratorServicePass implements CompilerPassInterface
|
||||
$container->setAlias($renamedId, new Alias($container->normalizeId($alias), false));
|
||||
} else {
|
||||
$decoratedDefinition = $container->getDefinition($inner);
|
||||
$definition->setTags(array_merge($decoratedDefinition->getTags(), $definition->getTags()));
|
||||
if ($types = array_merge($decoratedDefinition->getAutowiringTypes(false), $definition->getAutowiringTypes(false))) {
|
||||
$definition->setAutowiringTypes($types);
|
||||
}
|
||||
$public = $decoratedDefinition->isPublic();
|
||||
$private = $decoratedDefinition->isPrivate();
|
||||
$decoratedDefinition->setPublic(false);
|
||||
$decoratedDefinition->setTags(array());
|
||||
if ($decoratedDefinition->getAutowiringTypes(false)) {
|
||||
$decoratedDefinition->setAutowiringTypes(array());
|
||||
}
|
||||
$container->setDefinition($renamedId, $decoratedDefinition);
|
||||
$decoratingDefinitions[$inner] = $decoratedDefinition;
|
||||
}
|
||||
|
||||
if (isset($decoratingDefinitions[$inner])) {
|
||||
$decoratingDefinition = $decoratingDefinitions[$inner];
|
||||
$definition->setTags(array_merge($decoratingDefinition->getTags(), $definition->getTags()));
|
||||
$autowiringTypes = $decoratingDefinition->getAutowiringTypes(false);
|
||||
if ($types = array_merge($autowiringTypes, $definition->getAutowiringTypes(false))) {
|
||||
$definition->setAutowiringTypes($types);
|
||||
}
|
||||
$decoratingDefinition->setTags(array());
|
||||
if ($autowiringTypes) {
|
||||
$decoratingDefinition->setAutowiringTypes(array());
|
||||
}
|
||||
$decoratingDefinitions[$inner] = $definition;
|
||||
}
|
||||
|
||||
$container->setAlias($inner, $id)->setPublic($public)->setPrivate($private);
|
||||
|
@ -168,6 +168,29 @@ class DecoratorServicePassTest extends TestCase
|
||||
$this->assertEmpty($container->getDefinition('child.inner')->getAutowiringTypes());
|
||||
}
|
||||
|
||||
public function testProcessMovesTagsFromDecoratedDefinitionToDecoratingDefinitionMultipleTimes()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo')
|
||||
->setPublic(true)
|
||||
->setTags(array('bar' => array('attr' => 'baz')))
|
||||
;
|
||||
$container
|
||||
->register('deco1')
|
||||
->setDecoratedService('foo', null, 50)
|
||||
;
|
||||
$container
|
||||
->register('deco2')
|
||||
->setDecoratedService('foo', null, 2)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertEmpty($container->getDefinition('deco1')->getTags());
|
||||
$this->assertEquals(array('bar' => array('attr' => 'baz')), $container->getDefinition('deco2')->getTags());
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$repeatedPass = new DecoratorServicePass();
|
||||
|
Reference in New Issue
Block a user