Augmentation vers version 3.3.0
This commit is contained in:
@@ -35,21 +35,22 @@ class RemoveUnusedDefinitionsPass implements RepeatablePassInterface
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$compiler = $container->getCompiler();
|
||||
$formatter = $compiler->getLoggingFormatter();
|
||||
$graph = $compiler->getServiceReferenceGraph();
|
||||
$graph = $container->getCompiler()->getServiceReferenceGraph();
|
||||
|
||||
$hasChanged = false;
|
||||
foreach ($container->getDefinitions() as $id => $definition) {
|
||||
if ($definition->isPublic()) {
|
||||
if ($definition->isPublic() || $definition->isPrivate()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($graph->hasNode($id)) {
|
||||
$edges = $graph->getNode($id)->getInEdges();
|
||||
$referencingAliases = array();
|
||||
$sourceIds = array();
|
||||
$referencingAliases = [];
|
||||
$sourceIds = [];
|
||||
foreach ($edges as $edge) {
|
||||
if ($edge->isWeak()) {
|
||||
continue;
|
||||
}
|
||||
$node = $edge->getSourceNode();
|
||||
$sourceIds[] = $node->getId();
|
||||
|
||||
@@ -59,18 +60,20 @@ class RemoveUnusedDefinitionsPass implements RepeatablePassInterface
|
||||
}
|
||||
$isReferenced = (\count(array_unique($sourceIds)) - \count($referencingAliases)) > 0;
|
||||
} else {
|
||||
$referencingAliases = array();
|
||||
$referencingAliases = [];
|
||||
$isReferenced = false;
|
||||
}
|
||||
|
||||
if (1 === \count($referencingAliases) && false === $isReferenced) {
|
||||
$container->setDefinition((string) reset($referencingAliases), $definition);
|
||||
$definition->setPublic(true);
|
||||
$definition->setPublic(!$definition->isPrivate());
|
||||
$definition->setPrivate(reset($referencingAliases)->isPrivate());
|
||||
$container->removeDefinition($id);
|
||||
$compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'replaces alias '.reset($referencingAliases)));
|
||||
$container->log($this, sprintf('Removed service "%s"; reason: replaces alias %s.', $id, reset($referencingAliases)));
|
||||
} elseif (0 === \count($referencingAliases) && false === $isReferenced) {
|
||||
$container->removeDefinition($id);
|
||||
$compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'unused'));
|
||||
$container->resolveEnvPlaceholders(serialize($definition));
|
||||
$container->log($this, sprintf('Removed service "%s"; reason: unused.', $id));
|
||||
$hasChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user