Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
RemoveUnusedDefinitionsPass.php
01 <?php
02
03 /*
04 * This file is part of the Symfony package.
05 *
06 * (c) Fabien Potencier <fabien@symfony.com>
07 *
08 * For the full copyright and license information, please view the LICENSE
09 * 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 * @param ContainerBuilder $container
37 */
38 public function process(ContainerBuilder $container)
39 {
40 $compiler = $container->getCompiler();
41 $formatter = $compiler->getLoggingFormatter();
42 $graph = $compiler->getServiceReferenceGraph();
43
44 $hasChanged = false;
45 foreach ($container->getDefinitions() as $id => $definition) {
46 if ($definition->isPublic()) {
47 continue;
48 }
49
50 if ($graph->hasNode($id)) {
51 $edges = $graph->getNode($id)->getInEdges();
52 $referencingAliases = array();
53 $sourceIds = array();
54 foreach ($edges as $edge) {
55 $node = $edge->getSourceNode();
56 $sourceIds[] = $node->getId();
57
58 if ($node->isAlias()) {
59 $referencingAliases[] = $node->getValue();
60 }
61 }
62 $isReferenced = (count(array_unique($sourceIds)) - count($referencingAliases)) > 0;
63 } else {
64 $referencingAliases = array();
65 $isReferenced = false;
66 }
67
68 if (1 === count($referencingAliases) && false === $isReferenced) {
69 $container->setDefinition((string) reset($referencingAliases), $definition);
70 $definition->setPublic(true);
71 $container->removeDefinition($id);
72 $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'replaces alias '.reset($referencingAliases)));
73 } elseif (0 === count($referencingAliases) && false === $isReferenced) {
74 $container->removeDefinition($id);
75 $compiler->addLogMessage($formatter->formatRemoveService($this, $id, 'unused'));
76 $hasChanged = true;
77 }
78 }
79
80 if ($hasChanged) {
81 $this->repeatedPass->setRepeat();
82 }
83 }
84 }
85