Merge branch '3.4' into 4.1
* 3.4: [DependencyInjection] Fix tags on multiple decorated service
This commit is contained in:
commit
25c2975cd4
@ -34,6 +34,7 @@ class DecoratorServicePass implements CompilerPassInterface
|
|||||||
}
|
}
|
||||||
$definitions->insert(array($id, $definition), array($decorated[2], --$order));
|
$definitions->insert(array($id, $definition), array($decorated[2], --$order));
|
||||||
}
|
}
|
||||||
|
$decoratingDefinitions = array();
|
||||||
|
|
||||||
foreach ($definitions as list($id, $definition)) {
|
foreach ($definitions as list($id, $definition)) {
|
||||||
list($inner, $renamedId) = $definition->getDecoratedService();
|
list($inner, $renamedId) = $definition->getDecoratedService();
|
||||||
@ -54,12 +55,18 @@ class DecoratorServicePass implements CompilerPassInterface
|
|||||||
$container->setAlias($renamedId, new Alias((string) $alias, false));
|
$container->setAlias($renamedId, new Alias((string) $alias, false));
|
||||||
} else {
|
} else {
|
||||||
$decoratedDefinition = $container->getDefinition($inner);
|
$decoratedDefinition = $container->getDefinition($inner);
|
||||||
$definition->setTags(array_merge($decoratedDefinition->getTags(), $definition->getTags()));
|
|
||||||
$public = $decoratedDefinition->isPublic();
|
$public = $decoratedDefinition->isPublic();
|
||||||
$private = $decoratedDefinition->isPrivate();
|
$private = $decoratedDefinition->isPrivate();
|
||||||
$decoratedDefinition->setPublic(false);
|
$decoratedDefinition->setPublic(false);
|
||||||
$decoratedDefinition->setTags(array());
|
|
||||||
$container->setDefinition($renamedId, $decoratedDefinition);
|
$container->setDefinition($renamedId, $decoratedDefinition);
|
||||||
|
$decoratingDefinitions[$inner] = $decoratedDefinition;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($decoratingDefinitions[$inner])) {
|
||||||
|
$decoratingDefinition = $decoratingDefinitions[$inner];
|
||||||
|
$definition->setTags(array_merge($decoratingDefinition->getTags(), $definition->getTags()));
|
||||||
|
$decoratingDefinition->setTags(array());
|
||||||
|
$decoratingDefinitions[$inner] = $definition;
|
||||||
}
|
}
|
||||||
|
|
||||||
$container->setAlias($inner, $id)->setPublic($public)->setPrivate($private);
|
$container->setAlias($inner, $id)->setPublic($public)->setPrivate($private);
|
||||||
|
@ -144,6 +144,29 @@ class DecoratorServicePassTest extends TestCase
|
|||||||
$this->assertEquals(array('bar' => array('attr' => 'baz'), 'foobar' => array('attr' => 'bar')), $container->getDefinition('baz')->getTags());
|
$this->assertEquals(array('bar' => array('attr' => 'baz'), 'foobar' => array('attr' => 'bar')), $container->getDefinition('baz')->getTags());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
protected function process(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$repeatedPass = new DecoratorServicePass();
|
$repeatedPass = new DecoratorServicePass();
|
||||||
|
Reference in New Issue
Block a user