From d6502952b49c9f708d2ea1a5384d290187352cca Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 29 Dec 2013 12:49:18 +0100 Subject: [PATCH] [DependencyInjection] fixed InlineServiceDefinitionsPass to not inline a service if it's part of the current definition (to avoid an infinite loop) --- .../Compiler/InlineServiceDefinitionsPass.php | 4 ++++ .../Compiler/InlineServiceDefinitionsPassTest.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php index 2868cca63fa8..ba1688f5e867 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php @@ -125,6 +125,10 @@ private function isInlineableDefinition(ContainerBuilder $container, $id, Defini return true; } + if ($this->currentId == $id) { + return false; + } + $ids = array(); foreach ($this->graph->getNode($id)->getInEdges() as $edge) { $ids[] = $edge->getSourceNode()->getId(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php index 986e4047e9f4..6458a335d891 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/InlineServiceDefinitionsPassTest.php @@ -144,6 +144,21 @@ public function testProcessDoesNotInlineWhenServiceIsPrivateButLazy() $this->assertSame($ref, $arguments[0]); } + public function testProcessDoesNotInlineWhenServiceReferencesItself() + { + $container = new ContainerBuilder(); + $container + ->register('foo') + ->setPublic(false) + ->addMethodCall('foo', array($ref = new Reference('foo'))) + ; + + $this->process($container); + + $calls = $container->getDefinition('foo')->getMethodCalls(); + $this->assertSame($ref, $calls[0][1][0]); + } + protected function process(ContainerBuilder $container) { $repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new InlineServiceDefinitionsPass()));