[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\DependencyInjection\Compiler; 13 14 use Symfony\Component\DependencyInjection\ContainerBuilder; 15 16 /** 17 * Removes unused service definitions from the container. 18 * 19 * @author Johannes M. Schmitt <schmittjoh@gmail.com> 20 */ 21 class RemoveUnusedDefinitionsPass implements RepeatablePassInterface 22 { 23 private $repeatedPass; 24 25 /** 26 * {@inheritdoc} 27 */ 28 public function setRepeatedPass(RepeatedPass $repeatedPass) 29 { 30 $this->repeatedPass = $repeatedPass; 31 } 32 33 /** 34 * Processes the ContainerBuilder to remove unused definitions. 35 */ 36 public function process(ContainerBuilder $container) 37 { 38 $compiler = $container->getCompiler(); 39 $formatter = $compiler->getLoggingFormatter(); 40 $graph = $compiler->getServiceReferenceGraph(); 41 42 $hasChanged = false; 43 foreach ($container->getDefinitions() as $id => $definition) { 44 if ($definition->isPublic()) { 45 continue; 46 } 47 48 if ($graph->hasNode($id)) { 49 $edges = $graph->getNode($id)->getInEdges(); 50 $referencingAliases = array(); 51 $sourceIds = array(); 52 foreach ($edges as $edge) { 53 $node = $edge->getSourceNode(); 54 $sourceIds[] = $node->getId(); 55 56 if ($node->isAlias()) { 57 $referencingAliases[] = $node->getValue(); 58 } 59 } 60 $isReferenced = (\count(array_unique($sourceIds)) - \count($referencingAliases)) > 0; 61 } else { 62 $referencingAliases = array(); 63 $isReferenced = false; 64 } 65 66 if (1 === \count($referencingAliases) && false === $isReferenced) { 67 $container->setDefinition((string) reset($referencingAliases), $definition); 68 $definition->setPublic(true); 69 $container->removeDefinition($id); 70 $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'replaces alias '.reset($referencingAliases))); 71 } elseif (0 === \count($referencingAliases) && false === $isReferenced) { 72 $container->removeDefinition($id); 73 $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'unused')); 74 $hasChanged = true; 75 } 76 } 77 78 if ($hasChanged) { 79 $this->repeatedPass->setRepeat(); 80 } 81 } 82 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |