bug #20207 [DependencyInjection] move tags from decorated to decorating service (xabbuh)
This PR was merged into the 2.7 branch.
Discussion
----------
[DependencyInjection] move tags from decorated to decorating service
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #20150
| License | MIT
| Doc PR |
Commits
-------
7def83c
move tags from decorated to decorating service
This commit is contained in:
commit
7e2f24fc6f
|
@ -42,10 +42,12 @@ class DecoratorServicePass implements CompilerPassInterface
|
|||
$public = $alias->isPublic();
|
||||
$container->setAlias($renamedId, new Alias((string) $alias, false));
|
||||
} else {
|
||||
$definition = $container->getDefinition($inner);
|
||||
$public = $definition->isPublic();
|
||||
$definition->setPublic(false);
|
||||
$container->setDefinition($renamedId, $definition);
|
||||
$decoratedDefinition = $container->getDefinition($inner);
|
||||
$definition->setTags($decoratedDefinition->getTags(), $definition->getTags());
|
||||
$public = $decoratedDefinition->isPublic();
|
||||
$decoratedDefinition->setPublic(false);
|
||||
$decoratedDefinition->setTags(array());
|
||||
$container->setDefinition($renamedId, $decoratedDefinition);
|
||||
}
|
||||
|
||||
$container->setAlias($inner, new Alias($id, $public));
|
||||
|
|
|
@ -82,6 +82,24 @@ class DecoratorServicePassTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertNull($fooExtendedDefinition->getDecoratedService());
|
||||
}
|
||||
|
||||
public function testProcessMovesTagsFromDecoratedDefinitionToDecoratingDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo')
|
||||
->setTags(array('name' => 'bar'))
|
||||
;
|
||||
$container
|
||||
->register('baz')
|
||||
->setDecoratedService('foo')
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertEmpty($container->getDefinition('baz.inner')->getTags());
|
||||
$this->assertEquals(array('name' => 'bar'), $container->getDefinition('baz')->getTags());
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$repeatedPass = new DecoratorServicePass();
|
||||
|
|
Reference in New Issue