function InlineServiceDefinitionsPass::process
Overrides AbstractRecursivePass::process
File
-
vendor/
symfony/ dependency-injection/ Compiler/ InlineServiceDefinitionsPass.php, line 41
Class
- InlineServiceDefinitionsPass
- Inline service definitions where this is possible.
Namespace
Symfony\Component\DependencyInjection\CompilerCode
public function process(ContainerBuilder $container) : void {
$this->container = $container;
if ($this->analyzingPass) {
$analyzedContainer = new ContainerBuilder();
$analyzedContainer->setAliases($container->getAliases());
$analyzedContainer->setDefinitions($container->getDefinitions());
foreach ($container->getExpressionLanguageProviders() as $provider) {
$analyzedContainer->addExpressionLanguageProvider($provider);
}
}
else {
$analyzedContainer = $container;
}
try {
$notInlinableIds = [];
$remainingInlinedIds = [];
$this->connectedIds = $this->notInlinedIds = $container->getDefinitions();
do {
if ($this->analyzingPass) {
$analyzedContainer->setDefinitions(array_intersect_key($analyzedContainer->getDefinitions(), $this->connectedIds));
$this->analyzingPass
->process($analyzedContainer);
}
$this->graph = $analyzedContainer->getCompiler()
->getServiceReferenceGraph();
$notInlinedIds = $this->notInlinedIds;
$notInlinableIds += $this->notInlinableIds;
$this->connectedIds = $this->notInlinedIds = $this->inlinedIds = $this->notInlinableIds = [];
foreach ($analyzedContainer->getDefinitions() as $id => $definition) {
if (!$this->graph
->hasNode($id)) {
continue;
}
foreach ($this->graph
->getNode($id)
->getOutEdges() as $edge) {
if (isset($notInlinedIds[$edge->getSourceNode()
->getId()])) {
$this->currentId = $id;
$this->processValue($definition, true);
break;
}
}
}
foreach ($this->inlinedIds as $id => $isPublicOrNotShared) {
if ($isPublicOrNotShared) {
$remainingInlinedIds[$id] = $id;
}
else {
$container->removeDefinition($id);
$analyzedContainer->removeDefinition($id);
}
}
} while ($this->inlinedIds && $this->analyzingPass);
foreach ($remainingInlinedIds as $id) {
if (isset($notInlinableIds[$id])) {
continue;
}
$definition = $container->getDefinition($id);
if (!$definition->isShared() && !$definition->isPublic()) {
$container->removeDefinition($id);
}
}
} finally {
$this->container = null;
$this->connectedIds = $this->notInlinedIds = $this->inlinedIds = [];
$this->notInlinableIds = [];
$this->graph = null;
}
}