Ver Fonte

[DependencyInjection] fixed un-detected circular references involving aliases

Fabien Potencier há 14 anos atrás
pai
commit
e718a51b59

+ 9 - 2
src/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php

@@ -95,7 +95,7 @@ class AnalyzeServiceReferencesPass implements RepeatablePassInterface
                 $this->graph->connect(
                 $this->graph->connect(
                     $this->currentId,
                     $this->currentId,
                     $this->currentDefinition,
                     $this->currentDefinition,
-                    (string) $argument,
+                    $this->getDefinitionId((string) $argument),
                     $this->getDefinition((string) $argument),
                     $this->getDefinition((string) $argument),
                     $argument
                     $argument
                 );
                 );
@@ -114,6 +114,13 @@ class AnalyzeServiceReferencesPass implements RepeatablePassInterface
      * @return Definition The definition related to the supplied id
      * @return Definition The definition related to the supplied id
      */
      */
     private function getDefinition($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)) {
         while ($this->container->hasAlias($id)) {
             $id = (string) $this->container->getAlias($id);
             $id = (string) $this->container->getAlias($id);
@@ -123,6 +130,6 @@ class AnalyzeServiceReferencesPass implements RepeatablePassInterface
             return null;
             return null;
         }
         }
 
 
-        return $this->container->getDefinition($id);
+        return $id;
     }
     }
 }
 }

+ 13 - 0
tests/Symfony/Tests/Component/DependencyInjection/Compiler/CheckCircularReferencesPassTest.php

@@ -35,6 +35,19 @@ class CheckCircularReferencesPassTest extends \PHPUnit_Framework_TestCase
         $this->process($container);
         $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
      * @expectedException \RuntimeException
      */
      */