Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,6 +43,7 @@ public function process(ContainerBuilder $container)
$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) {
Expand Down Expand Up @@ -76,6 +78,15 @@ private function processArguments(array $arguments)
return $arguments;
}

private function processFactoryService($factoryService)
{
if (null === $factoryService) {
return;
}

return $this->getDefinitionId($factoryService);
}

/**
* Resolves an alias into a definition id.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,6 +61,21 @@ public function testAliasCircularReference()
$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();
Expand Down