Skip to content

Commit

Permalink
Merge branch '4.4' into 5.0
Browse files Browse the repository at this point in the history
* 4.4:
  Fix closing tag in mailer collector template
  [HttpClient] Don't read from the network faster than the CPU can deal with
  [DI] DecoratorServicePass should keep container.service_locator on the decorated definition
  • Loading branch information
nicolas-grekas committed Jan 6, 2020
2 parents 7fb463a + cc3812c commit 5292e03
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Compiler/DecoratorServicePass.php
Expand Up @@ -78,8 +78,18 @@ public function process(ContainerBuilder $container)

if (isset($decoratingDefinitions[$inner])) {
$decoratingDefinition = $decoratingDefinitions[$inner];
$definition->setTags(array_merge($decoratingDefinition->getTags(), $definition->getTags()));
$decoratingDefinition->setTags([]);

$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']);
}

$definition->setTags(array_merge($decoratingTags, $definition->getTags()));
$decoratingDefinition->setTags($resetTags);
$decoratingDefinitions[$inner] = $definition;
}

Expand Down
19 changes: 19 additions & 0 deletions Tests/Compiler/DecoratorServicePassTest.php
Expand Up @@ -223,6 +223,25 @@ public function testProcessMovesTagsFromDecoratedDefinitionToDecoratingDefinitio
$this->assertEquals(['bar' => ['attr' => 'baz']], $container->getDefinition('deco2')->getTags());
}

public function testProcessLeavesServiceLocatorTagOnOriginalDefinition()
{
$container = new ContainerBuilder();
$container
->register('foo')
->setTags(['container.service_locator' => [0 => []], 'bar' => ['attr' => 'baz']])
;
$container
->register('baz')
->setTags(['foobar' => ['attr' => 'bar']])
->setDecoratedService('foo')
;

$this->process($container);

$this->assertEquals(['container.service_locator' => [0 => []]], $container->getDefinition('baz.inner')->getTags());
$this->assertEquals(['bar' => ['attr' => 'baz'], 'foobar' => ['attr' => 'bar']], $container->getDefinition('baz')->getTags());
}

protected function process(ContainerBuilder $container)
{
$pass = new DecoratorServicePass();
Expand Down

0 comments on commit 5292e03

Please sign in to comment.