* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\ContainerBuilder; /** * Removes unused service definitions from the container. * * @author Johannes M. Schmitt */ class RemoveUnusedDefinitionsPass implements RepeatablePassInterface { private $repeatedPass; /** * {@inheritdoc} */ public function setRepeatedPass(RepeatedPass $repeatedPass) { $this->repeatedPass = $repeatedPass; } /** * Processes the ContainerBuilder to remove unused definitions. */ public function process(ContainerBuilder $container) { $graph = $container->getCompiler()->getServiceReferenceGraph(); $hasChanged = false; foreach ($container->getDefinitions() as $id => $definition) { if ($definition->isPublic() || $definition->isPrivate()) { continue; } if ($graph->hasNode($id)) { $edges = $graph->getNode($id)->getInEdges(); $referencingAliases = array(); $sourceIds = array(); foreach ($edges as $edge) { if ($edge->isWeak()) { continue; } $node = $edge->getSourceNode(); $sourceIds[] = $node->getId(); if ($node->isAlias()) { $referencingAliases[] = $node->getValue(); } } $isReferenced = (count(array_unique($sourceIds)) - count($referencingAliases)) > 0; } else { $referencingAliases = array(); $isReferenced = false; } if (1 === count($referencingAliases) && false === $isReferenced) { $container->setDefinition((string) reset($referencingAliases), $definition); $definition->setPublic(!$definition->isPrivate()); $definition->setPrivate(reset($referencingAliases)->isPrivate()); $container->removeDefinition($id); $container->log($this, sprintf('Removed service "%s"; reason: replaces alias %s.', $id, reset($referencingAliases))); } elseif (0 === count($referencingAliases) && false === $isReferenced) { $container->removeDefinition($id); $container->resolveEnvPlaceholders(serialize($definition)); $container->log($this, sprintf('Removed service "%s"; reason: unused.', $id)); $hasChanged = true; } } if ($hasChanged) { $this->repeatedPass->setRepeat(); } } } __halt_compiler();----SIGNATURE:----rwfIpvvNlj2ttzmyDpcNuB6GG+T5rghS6fPdv9w33zDewaVZvMPeTg3SF/2p27xv6gV/biijepE8JN0rLkhBCIvxnea3cH0rw606lGqMkIPIlxuOstqkPGavqbxotmyEEDUTbbvc7W9tc5JhMquqKqILD5oNrU3lykl83dsFR5RPrI5xyWF9Gkg7u1kIswVeCtOWsnWg1PAUVk+3gbO/3sQkfA54OfbT5g1XVqHVkJr0d34vVWtQtRx5noYKx1q6VJGLVvLXamCPF0dPfyHESZUsuw+M5uIBKj2bPglQijHyhOWY1dwCkx6aaEpjQdTdivheYbo91EHFrV1akO2WnVdLoMW2zwooj/rcOlkOFNZtjUe6LuzTeKDVk9S+xpW+RPfeFYRiWG7fPID1z9q1SQIqLetaO2Hu4VPx36QloiJwkPUptsfondXOatAmCxR41nJUoyDV94RP+eLsObf3J9/iKYxLR3yC8l6TCnnhGdqXTc4XEkOYwX2rhxYCGfHVF3YEsU0llJ2XNtfEzcOgs+KIFPpa3g4FeZawqxuGVZsm1pGSNWDUiRBLsim6O3UIsRbCv9KiRTo1vhFUHvmrgj9NZlScl4hhLsI3jv2s0pFh5az3al43oFCGaPLOn9F1zd7BCKGeAG6UUMMCiOnrzLb70PZcJ1q/96pnBl+Z2nE=----ATTACHMENT:----NzY2ODU3NjA5Njk3MTE2MSA1MzU0NDQyNTQ4MzUxMDkxIDg1MjI2MTE0MjMyNDIyNzk=