From e718a51b595ab80bf5352727380348b9392b0f9f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 11 Jul 2011 18:25:40 +0200 Subject: [PATCH] [DependencyInjection] fixed un-detected circular references involving aliases --- .../Compiler/AnalyzeServiceReferencesPass.php | 11 +++++++++-- .../Compiler/CheckCircularReferencesPassTest.php | 13 +++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php index 2399f6ca1218..2160d47cb5a6 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php @@ -95,7 +95,7 @@ private function processArguments(array $arguments) $this->graph->connect( $this->currentId, $this->currentDefinition, - (string) $argument, + $this->getDefinitionId((string) $argument), $this->getDefinition((string) $argument), $argument ); @@ -114,6 +114,13 @@ private function processArguments(array $arguments) * @return Definition The definition related to the supplied id */ private function getDefinition($id) + { + $id = $this->getDefinitionId($id); + + return null === $id ? null : $this->container->getDefinition($id); + } + + private function getDefinitionId($id) { while ($this->container->hasAlias($id)) { $id = (string) $this->container->getAlias($id); @@ -123,6 +130,6 @@ private function getDefinition($id) return null; } - return $this->container->getDefinition($id); + return $id; } } diff --git a/tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckCircularReferencesPassTest.php b/tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckCircularReferencesPassTest.php index 8955a6eb0e0e..079c13d461fc 100644 --- a/tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckCircularReferencesPassTest.php +++ b/tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckCircularReferencesPassTest.php @@ -35,6 +35,19 @@ public function testProcess() $this->process($container); } + /** + * @expectedException \RuntimeException + */ + public function testProcessWithAliases() + { + $container = new ContainerBuilder(); + $container->register('a')->addArgument(new Reference('b')); + $container->setAlias('b', 'c'); + $container->setAlias('c', 'a'); + + $this->process($container); + } + /** * @expectedException \RuntimeException */