Skip to content
Permalink
Browse files

bug #28820 [DependencyInjection] Fix tags on multiple decorated servi…

…ce (Soner Sayakci)

This PR was merged into the 3.4 branch.

Discussion
----------

[DependencyInjection] Fix tags on multiple decorated service

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28682
| License       | MIT
| Doc PR        |

After the first run in the loop with the same decorated service it goes only in the hasAlias condition. The tags will be not set here, so the `ResolveTaggedIteratorArgumentPass` will handle only the first decoration.

Commits
-------

90f8df2 [DependencyInjection] Fix tags on multiple decorated service
  • Loading branch information...
nicolas-grekas committed Oct 31, 2018
2 parents bcc4454 + 90f8df2 commit 5d1120593c4728304167ca856265bb03dd4fd152
@@ -34,6 +34,7 @@ public function process(ContainerBuilder $container)
}
$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 @@ public function process(ContainerBuilder $container)
$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 @@ public function testProcessMergesAutowiringTypesInDecoratingDefinitionAndRemoveT
$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();

0 comments on commit 5d11205

Please sign in to comment.
You can’t perform that action at this time.