8000 resolve aliases in factory services · symfony/symfony@7702189 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7702189

Browse files
committed
resolve aliases in factory services
1 parent 025f761 commit 7702189

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/Symfony/Component/DependencyInjection/Compiler/ResolveReferencesToAliasesPass.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

1414
use Symfony\Component\DependencyInjection\Alias;
15+
use Symfony\Component\DependencyInjection\Definition;
1516
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
1617
use Symfony\Component\DependencyInjection\Reference;
1718
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -42,6 +43,7 @@ public function process(ContainerBuilder $container)
4243
$definition->setArguments($this->processArguments($definition->getArguments()));
4344
$definition->setMethodCalls($this->processArguments($definition->getMethodCalls()));
4445
$definition->setProperties($this->processArguments($definition->getProperties()));
46+
$definition->setFactoryService($this->processFactoryService($definition->getFactoryService()));
4547
}
4648

4749
foreach ($container->getAliases() as $id => $alias) {
@@ -76,6 +78,15 @@ private function processArguments(array $arguments)
7678
return $arguments;
7779
}
7880

81+
private function processFactoryService($factoryService)
82+
{
83+
if (null === $factoryService) {
84+
return;
85+
}
86+
87+
return $this->getDefinitionId($factoryService);
88+
}
89+
7990
/**
8091
* Resolves an alias into a definition id.
8192
*

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveReferencesToAliasesPassTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
1313

14+
use Symfony\Component\DependencyInjection\Alias;
15+
use Symfony\Component\DependencyInjection\Definition;
1416
use Symfony\Component\DependencyInjection\Reference;
1517
use Symfony\Component\DependencyInjection\Compiler\ResolveReferencesToAliasesPass;
1618
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -59,6 +61,21 @@ public function testAliasCircularReference()
5961
$this->process($container);
6062
}
6163

64+
public function testResolveFactory()
65+
{
66+
$container = new ContainerBuilder();
67+
$container->register('factory', 'Factory');
68+
$container->setAlias('factory_alias', new Alias('factory'));
69+
$foo = new Definition();
70+
$foo->setFactoryService('factory_alias');
71+
$foo->setFactoryMethod('createFoo');
72+
$container->setDefinition('foo', $foo);
73+
74+
$this->process($container);
75+
76+
$this->assertSame('factory', $foo->getFactoryService());
77+
}
78+
6279
protected function process(ContainerBuilder $container)
6380
{
6481
$pass = new ResolveReferencesToAliasesPass();

0 commit comments

Comments
 (0)
0