AnalyzeServiceReferencesPass.php in Service Container 7
File
modules/providers/service_container_symfony/lib/Symfony/Component/DependencyInjection/Compiler/AnalyzeServiceReferencesPass.php
View source
<?php
namespace Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class AnalyzeServiceReferencesPass implements RepeatablePassInterface {
private $graph;
private $container;
private $currentId;
private $currentDefinition;
private $repeatedPass;
private $onlyConstructorArguments;
public function __construct($onlyConstructorArguments = false) {
$this->onlyConstructorArguments = (bool) $onlyConstructorArguments;
}
public function setRepeatedPass(RepeatedPass $repeatedPass) {
$this->repeatedPass = $repeatedPass;
}
public function process(ContainerBuilder $container) {
$this->container = $container;
$this->graph = $container
->getCompiler()
->getServiceReferenceGraph();
$this->graph
->clear();
foreach ($container
->getDefinitions() as $id => $definition) {
if ($definition
->isSynthetic() || $definition
->isAbstract()) {
continue;
}
$this->currentId = $id;
$this->currentDefinition = $definition;
$this
->processArguments($definition
->getArguments());
if ($definition
->getFactoryService(false)) {
$this
->processArguments(array(
new Reference($definition
->getFactoryService(false)),
));
}
if (is_array($definition
->getFactory())) {
$this
->processArguments($definition
->getFactory());
}
if (!$this->onlyConstructorArguments) {
$this
->processArguments($definition
->getMethodCalls());
$this
->processArguments($definition
->getProperties());
if ($definition
->getConfigurator()) {
$this
->processArguments(array(
$definition
->getConfigurator(),
));
}
}
}
foreach ($container
->getAliases() as $id => $alias) {
$this->graph
->connect($id, $alias, (string) $alias, $this
->getDefinition((string) $alias), null);
}
}
private function processArguments(array $arguments) {
foreach ($arguments as $argument) {
if (is_array($argument)) {
$this
->processArguments($argument);
}
elseif ($argument instanceof Reference) {
$this->graph
->connect($this->currentId, $this->currentDefinition, $this
->getDefinitionId((string) $argument), $this
->getDefinition((string) $argument), $argument);
}
elseif ($argument instanceof Definition) {
$this
->processArguments($argument
->getArguments());
$this
->processArguments($argument
->getMethodCalls());
$this
->processArguments($argument
->getProperties());
if (is_array($argument
->getFactory())) {
$this
->processArguments($argument
->getFactory());
}
if ($argument
->getFactoryService(false)) {
$this
->processArguments(array(
new Reference($argument
->getFactoryService(false)),
));
}
}
}
}
private function getDefinition($id) {
$id = $this
->getDefinitionId($id);
return null === $id ? null : $this->container
->getDefinition($id);
}
private function getDefinitionId($id) {
while ($this->container
->hasAlias($id)) {
$id = (string) $this->container
->getAlias($id);
}
if (!$this->container
->hasDefinition($id)) {
return;
}
return $id;
}
}