From 7702189cb43972f08acbca14ae524bbf5576f0cb Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 27 Jan 2016 08:44:59 +0100 Subject: [PATCH] resolve aliases in factory services --- .../Compiler/ResolveReferencesToAliasesPass.php | 11 +++++++++++ .../ResolveReferencesToAliasesPassTest.php | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php b/src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php index c90d76f48a..0167786523 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php @@ -12,6 +12,7 @@ namespace Symfony\Component\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\Alias; +use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -42,6 +43,7 @@ class ResolveReferencesToAliasesPass implements CompilerPassInterface $definition->setArguments($this->processArguments($definition->getArguments())); $definition->setMethodCalls($this->processArguments($definition->getMethodCalls())); $definition->setProperties($this->processArguments($definition->getProperties())); + $definition->setFactoryService($this->processFactoryService($definition->getFactoryService())); } foreach ($container->getAliases() as $id => $alias) { @@ -76,6 +78,15 @@ class ResolveReferencesToAliasesPass implements CompilerPassInterface return $arguments; } + private function processFactoryService($factoryService) + { + if (null === $factoryService) { + return; + } + + return $this->getDefinitionId($factoryService); + } + /** * Resolves an alias into a definition id. * diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveReferencesToAliasesPassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveReferencesToAliasesPassTest.php index 6fdc233941..c441548fc4 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveReferencesToAliasesPassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveReferencesToAliasesPassTest.php @@ -11,6 +11,8 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler; +use Symfony\Component\DependencyInjection\Alias; +use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Compiler\ResolveReferencesToAliasesPass; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -59,6 +61,21 @@ class ResolveReferencesToAliasesPassTest extends \PHPUnit_Framework_TestCase $this->process($container); } + public function testResolveFactory() + { + $container = new ContainerBuilder(); + $container->register('factory', 'Factory'); + $container->setAlias('factory_alias', new Alias('factory')); + $foo = new Definition(); + $foo->setFactoryService('factory_alias'); + $foo->setFactoryMethod('createFoo'); + $container->setDefinition('foo', $foo); + + $this->process($container); + + $this->assertSame('factory', $foo->getFactoryService()); + } + protected function process(ContainerBuilder $container) { $pass = new ResolveReferencesToAliasesPass();