2011-01-05 11:13:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-01-15 13:29:43 +00:00
|
|
|
* This file is part of the Symfony package.
|
2011-01-05 11:13:27 +00:00
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
|
|
*
|
2011-01-15 13:29:43 +00:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
2011-01-05 11:13:27 +00:00
|
|
|
*/
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
namespace Symfony\Component\DependencyInjection\Compiler;
|
|
|
|
|
|
|
|
use Symfony\Component\DependencyInjection\Alias;
|
|
|
|
use Symfony\Component\DependencyInjection\Reference;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
|
2011-01-05 11:13:27 +00:00
|
|
|
/**
|
|
|
|
* Replaces all references to aliases with references to the actual service.
|
|
|
|
*
|
|
|
|
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
|
|
|
*/
|
|
|
|
class ResolveReferencesToAliasesPass implements CompilerPassInterface
|
|
|
|
{
|
|
|
|
protected $container;
|
|
|
|
|
|
|
|
public function process(ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
$this->container = $container;
|
|
|
|
|
|
|
|
foreach ($container->getDefinitions() as $id => $definition)
|
|
|
|
{
|
|
|
|
$definition->setArguments($this->processArguments($definition->getArguments()));
|
|
|
|
$definition->setMethodCalls($this->processArguments($definition->getMethodCalls()));
|
|
|
|
}
|
2011-01-07 14:44:29 +00:00
|
|
|
|
|
|
|
foreach ($container->getAliases() as $id => $alias) {
|
|
|
|
$aliasId = (string) $alias;
|
|
|
|
if ($aliasId !== $defId = $this->getDefinitionId($aliasId)) {
|
|
|
|
$container->setAlias($id, new Alias($defId, $alias->isPublic()));
|
|
|
|
}
|
|
|
|
}
|
2011-01-05 11:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function processArguments(array $arguments)
|
|
|
|
{
|
|
|
|
foreach ($arguments as $k => $argument) {
|
|
|
|
if (is_array($argument)) {
|
|
|
|
$arguments[$k] = $this->processArguments($argument);
|
|
|
|
} else if ($argument instanceof Reference) {
|
|
|
|
$defId = $this->getDefinitionId($id = (string) $argument);
|
|
|
|
|
|
|
|
if ($defId !== $id) {
|
2011-01-22 15:05:51 +00:00
|
|
|
$arguments[$k] = new Reference($defId, $argument->getInvalidBehavior(), $argument->isStrict());
|
2011-01-05 11:13:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $arguments;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getDefinitionId($id)
|
|
|
|
{
|
|
|
|
if ($this->container->hasAlias($id)) {
|
2011-01-07 14:44:29 +00:00
|
|
|
return $this->getDefinitionId((string) $this->container->getAlias($id));
|
2011-01-05 11:13:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $id;
|
|
|
|
}
|
|
|
|
}
|