diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php index 8308937d4a512..cb79c111afc41 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ReplaceAliasByActualDefinitionPass.php @@ -95,6 +95,8 @@ private function updateReferences($container, $currentId, $newId) $definition->setProperties( $this->updateArgumentReferences($definition->getProperties(), $currentId, $newId) ); + + $definition->setFactory($this->updateFactoryReference($definition->getFactory(), $currentId, $newId)); } } @@ -122,4 +124,17 @@ private function updateArgumentReferences(array $arguments, $currentId, $newId) return $arguments; } + + private function updateFactoryReference($factory, $currentId, $newId) + { + if (null === $factory || !is_array($factory) || !$factory[0] instanceof Reference) { + return $factory; + } + + if ($currentId === (string) $factory[0]) { + $factory[0] = new Reference($newId, $factory[0]->getInvalidBehavior()); + } + + return $factory; + } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php index e4d22401d3cdd..5311f5718bd61 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ReplaceAliasByActualDefinitionPassTest.php @@ -14,6 +14,7 @@ use Symfony\Component\DependencyInjection\Compiler\ReplaceAliasByActualDefinitionPass; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Reference; class ReplaceAliasByActualDefinitionPassTest extends \PHPUnit_Framework_TestCase { @@ -21,7 +22,8 @@ public function testProcess() { $container = new ContainerBuilder(); - $container->register('a', '\stdClass'); + $aDefinition = $container->register('a', '\stdClass'); + $aDefinition->setFactory(array(new Reference('b'), 'createA')); $bDefinition = new Definition('\stdClass'); $bDefinition->setPublic(false); @@ -39,6 +41,9 @@ public function testProcess() $container->has('b_alias') && !$container->hasAlias('b_alias'), '->process() replaces alias to actual.' ); + + $resolvedFactory = $aDefinition->getFactory(); + $this->assertSame('b_alias', (string) $resolvedFactory[0]); } /**
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: