keep container.service_subscriber tag on the decorated definition
This commit is contained in:
parent
7ccda8eedb
commit
b917fafc8d
@ -82,10 +82,12 @@ class DecoratorServicePass implements CompilerPassInterface
|
||||
$decoratingTags = $decoratingDefinition->getTags();
|
||||
$resetTags = [];
|
||||
|
||||
if (isset($decoratingTags['container.service_locator'])) {
|
||||
// container.service_locator has special logic and it must not be transferred out to decorators
|
||||
$resetTags = ['container.service_locator' => $decoratingTags['container.service_locator']];
|
||||
unset($decoratingTags['container.service_locator']);
|
||||
// container.service_locator and container.service_subscriber have special logic and they must not be transferred out to decorators
|
||||
foreach (['container.service_locator', 'container.service_subscriber'] as $containerTag) {
|
||||
if (isset($decoratingTags[$containerTag])) {
|
||||
$resetTags[$containerTag] = $decoratingTags[$containerTag];
|
||||
unset($decoratingTags[$containerTag]);
|
||||
}
|
||||
}
|
||||
|
||||
$definition->setTags(array_merge($decoratingTags, $definition->getTags()));
|
||||
|
@ -243,6 +243,25 @@ class DecoratorServicePassTest extends TestCase
|
||||
$this->assertEquals(['bar' => ['attr' => 'baz'], 'foobar' => ['attr' => 'bar']], $container->getDefinition('baz')->getTags());
|
||||
}
|
||||
|
||||
public function testProcessLeavesServiceSubscriberTagOnOriginalDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo')
|
||||
->setTags(['container.service_subscriber' => [], 'bar' => ['attr' => 'baz']])
|
||||
;
|
||||
$container
|
||||
->register('baz')
|
||||
->setTags(['foobar' => ['attr' => 'bar']])
|
||||
->setDecoratedService('foo')
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertEquals(['container.service_subscriber' => []], $container->getDefinition('baz.inner')->getTags());
|
||||
$this->assertEquals(['bar' => ['attr' => 'baz'], 'foobar' => ['attr' => 'bar']], $container->getDefinition('baz')->getTags());
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$repeatedPass = new DecoratorServicePass();
|
||||
|
Reference in New Issue
Block a user