Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
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 |
AnalyzeServiceReferencesPass.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\DependencyInjection\Compiler;
013
014 use Symfony\Component\DependencyInjection\Definition;
015 use Symfony\Component\DependencyInjection\Reference;
016 use Symfony\Component\DependencyInjection\ContainerBuilder;
017
018 /**
019 * Run this pass before passes that need to know more about the relation of
020 * your services.
021 *
022 * This class will populate the ServiceReferenceGraph with information. You can
023 * retrieve the graph in other passes from the compiler.
024 *
025 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
026 */
027 class AnalyzeServiceReferencesPass implements RepeatablePassInterface
028 {
029 private $graph;
030 private $container;
031 private $currentId;
032 private $currentDefinition;
033 private $repeatedPass;
034 private $onlyConstructorArguments;
035
036 /**
037 * @param bool $onlyConstructorArguments Sets this Service Reference pass to ignore method calls
038 */
039 public function __construct($onlyConstructorArguments = false)
040 {
041 $this->onlyConstructorArguments = (bool) $onlyConstructorArguments;
042 }
043
044 /**
045 * {@inheritdoc}
046 */
047 public function setRepeatedPass(RepeatedPass $repeatedPass)
048 {
049 $this->repeatedPass = $repeatedPass;
050 }
051
052 /**
053 * Processes a ContainerBuilder object to populate the service reference graph.
054 *
055 * @param ContainerBuilder $container
056 */
057 public function process(ContainerBuilder $container)
058 {
059 $this->container = $container;
060 $this->graph = $container->getCompiler()->getServiceReferenceGraph();
061 $this->graph->clear();
062
063 foreach ($container->getDefinitions() as $id => $definition) {
064 if ($definition->isSynthetic() || $definition->isAbstract()) {
065 continue;
066 }
067
068 $this->currentId = $id;
069 $this->currentDefinition = $definition;
070
071 $this->processArguments($definition->getArguments());
072 if ($definition->getFactoryService(false)) {
073 $this->processArguments(array(new Reference($definition->getFactoryService(false))));
074 }
075 if (is_array($definition->getFactory())) {
076 $this->processArguments($definition->getFactory());
077 }
078
079 if (!$this->onlyConstructorArguments) {
080 $this->processArguments($definition->getMethodCalls());
081 $this->processArguments($definition->getProperties());
082 if ($definition->getConfigurator()) {
083 $this->processArguments(array($definition->getConfigurator()));
084 }
085 }
086 }
087
088 foreach ($container->getAliases() as $id => $alias) {
089 $this->graph->connect($id, $alias, (string) $alias, $this->getDefinition((string) $alias), null);
090 }
091 }
092
093 /**
094 * Processes service definitions for arguments to find relationships for the service graph.
095 *
096 * @param array $arguments An array of Reference or Definition objects relating to service definitions
097 */
098 private function processArguments(array $arguments)
099 {
100 foreach ($arguments as $argument) {
101 if (is_array($argument)) {
102 $this->processArguments($argument);
103 } elseif ($argument instanceof Reference) {
104 $this->graph->connect(
105 $this->currentId,
106 $this->currentDefinition,
107 $this->getDefinitionId((string) $argument),
108 $this->getDefinition((string) $argument),
109 $argument
110 );
111 } elseif ($argument instanceof Definition) {
112 $this->processArguments($argument->getArguments());
113 $this->processArguments($argument->getMethodCalls());
114 $this->processArguments($argument->getProperties());
115
116 if (is_array($argument->getFactory())) {
117 $this->processArguments($argument->getFactory());
118 }
119 if ($argument->getFactoryService(false)) {
120 $this->processArguments(array(new Reference($argument->getFactoryService(false))));
121 }
122 }
123 }
124 }
125
126 /**
127 * Returns a service definition given the full name or an alias.
128 *
129 * @param string $id A full id or alias for a service definition
130 *
131 * @return Definition|null The definition related to the supplied id
132 */
133 private function getDefinition($id)
134 {
135 $id = $this->getDefinitionId($id);
136
137 return null === $id ? null : $this->container->getDefinition($id);
138 }
139
140 private function getDefinitionId($id)
141 {
142 while ($this->container->hasAlias($id)) {
143 $id = (string) $this->container->getAlias($id);
144 }
145
146 if (!$this->container->hasDefinition($id)) {
147 return;
148 }
149
150 return $id;
151 }
152 }
153