diff --git a/src/Symfony/Component/DependencyInjection/Compiler/CheckCircularReferencesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/CheckCircularReferencesPass.php index 9cb3ff060d..e3db1aabbd 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/CheckCircularReferencesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/CheckCircularReferencesPass.php @@ -56,11 +56,13 @@ class CheckCircularReferencesPass implements CompilerPassInterface private function checkOutEdges(array $edges) { foreach ($edges as $edge) { - $node = $edge->getDestNode(); - $this->currentPath[] = $id = $node->getId(); + $node = $edge->getDestNode(); + $id = $node->getId(); + $searchKey = array_search($id, $this->currentPath); + $this->currentPath[] = $id; - if ($this->currentId === $id) { - throw new ServiceCircularReferenceException($this->currentId, $this->currentPath); + if (false !== $searchKey) { + throw new ServiceCircularReferenceException($id, array_slice($this->currentPath, $searchKey)); } $this->checkOutEdges($node->getOutEdges()); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckCircularReferencesPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckCircularReferencesPassTest.php index 25f816b834..085bc519b7 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckCircularReferencesPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckCircularReferencesPassTest.php @@ -24,7 +24,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase { /** - * @expectedException \RuntimeException + * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException */ public function testProcess() { @@ -36,7 +36,7 @@ class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \RuntimeException + * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException */ public function testProcessWithAliases() { @@ -49,7 +49,7 @@ class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase } /** - * @expectedException \RuntimeException + * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException */ public function testProcessDetectsIndirectCircularReference() { @@ -61,6 +61,19 @@ class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase $this->process($container); } + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException + */ + public function testDeepCircularReference() + { + $container = new ContainerBuilder(); + $container->register('a')->addArgument(new Reference('b')); + $container->register('b')->addArgument(new Reference('c')); + $container->register('c')->addArgument(new Reference('b')); + + $this->process($container); + } + public function testProcessIgnoresMethodCalls() { $container = new ContainerBuilder();