bug #41407 [DependencyInjection] keep container.service_subscriber tag on the decorated definition (xabbuh)
This PR was merged into the 4.4 branch.
Discussion
----------
[DependencyInjection] keep container.service_subscriber tag on the decorated definition
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets |
| License | MIT
| Doc PR |
Commits
-------
b917fafc8d
keep container.service_subscriber tag on the decorated definition
This commit is contained in:
commit
519d348b4a
@ -82,10 +82,12 @@ class DecoratorServicePass implements CompilerPassInterface
|
|||||||
$decoratingTags = $decoratingDefinition->getTags();
|
$decoratingTags = $decoratingDefinition->getTags();
|
||||||
$resetTags = [];
|
$resetTags = [];
|
||||||
|
|
||||||
if (isset($decoratingTags['container.service_locator'])) {
|
// container.service_locator and container.service_subscriber have special logic and they must not be transferred out to decorators
|
||||||
// container.service_locator has special logic and it must not be transferred out to decorators
|
foreach (['container.service_locator', 'container.service_subscriber'] as $containerTag) {
|
||||||
$resetTags = ['container.service_locator' => $decoratingTags['container.service_locator']];
|
if (isset($decoratingTags[$containerTag])) {
|
||||||
unset($decoratingTags['container.service_locator']);
|
$resetTags[$containerTag] = $decoratingTags[$containerTag];
|
||||||
|
unset($decoratingTags[$containerTag]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$definition->setTags(array_merge($decoratingTags, $definition->getTags()));
|
$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());
|
$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)
|
protected function process(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$repeatedPass = new DecoratorServicePass();
|
$repeatedPass = new DecoratorServicePass();
|
||||||
|
Reference in New Issue
Block a user