瀏覽代碼

[DependencyInjection] fixes a bug which might have occurred when using property injection under certain circumstances

Johannes M. Schmitt 14 年之前
父節點
當前提交
1992c3b96d

+ 5 - 0
src/Symfony/Component/DependencyInjection/Compiler/LoggingFormatter.php

@@ -21,6 +21,11 @@ class LoggingFormatter
         return $this->format($pass, sprintf('Inlined service "%s" to "%s".', $id, $target));
     }
 
+    public function formatUpdateReference(CompilerPassInterface $pass, $serviceId, $oldDestId, $newDestId)
+    {
+        return $this->format($pass, sprintf('Changed reference of service "%s" previously pointing to "%s" to "%s".', $serviceId, $oldDestId, $newDestId));
+    }
+
     public function formatResolveInheritance(CompilerPassInterface $pass, $childId, $parentId)
     {
         return $this->format($pass, sprintf('Resolving inheritance for "%s" (parent: %s).', $childId, $parentId));

+ 16 - 2
src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php

@@ -22,13 +22,20 @@ use Symfony\Component\DependencyInjection\Reference;
  */
 class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface
 {
+    private $compiler;
+    private $formatter;
+    private $sourceId;
+
     /**
      * Process the Container to replace aliases with service definitions.
      *
-     * @param ContainerBuilder $container 
+     * @param ContainerBuilder $container
      */
     public function process(ContainerBuilder $container)
     {
+        $this->compiler = $container->getCompiler();
+        $this->formatter = $this->compiler->getLoggingFormatter();
+
         foreach ($container->getAliases() as $id => $alias) {
             $aliasId = (string) $alias;
 
@@ -67,7 +74,9 @@ class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface
             }
         }
 
-        foreach ($container->getDefinitions() as $definition) {
+        foreach ($container->getDefinitions() as $id => $definition) {
+            $this->sourceId = $id;
+
             $definition->setArguments(
                 $this->updateArgumentReferences($definition->getArguments(), $currentId, $newId)
             );
@@ -75,6 +84,10 @@ class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface
             $definition->setMethodCalls(
                 $this->updateArgumentReferences($definition->getMethodCalls(), $currentId, $newId)
             );
+
+            $definition->setProperties(
+                $this->updateArgumentReferences($definition->getProperties(), $currentId, $newId)
+            );
         }
     }
 
@@ -93,6 +106,7 @@ class ReplaceAliasByActualDefinitionPass implements CompilerPassInterface
             } else if ($argument instanceof Reference) {
                 if ($currentId === (string) $argument) {
                     $arguments[$k] = new Reference($newId, $argument->getInvalidBehavior());
+                    $this->compiler->addLogMessage($this->formatter->formatUpdateReference($this, $this->sourceId, $currentId, $newId));
                 }
             }
         }