Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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\Argument\ArgumentInterface;
015 use Symfony\Component\DependencyInjection\ContainerBuilder;
016 use Symfony\Component\DependencyInjection\ContainerInterface;
017 use Symfony\Component\DependencyInjection\Definition;
018 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
019 use Symfony\Component\DependencyInjection\ExpressionLanguage;
020 use Symfony\Component\DependencyInjection\Reference;
021 use Symfony\Component\ExpressionLanguage\Expression;
022
023 /**
024 * Run this pass before passes that need to know more about the relation of
025 * your services.
026 *
027 * This class will populate the ServiceReferenceGraph with information. You can
028 * retrieve the graph in other passes from the compiler.
029 *
030 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
031 */
032 class AnalyzeServiceReferencesPass extends AbstractRecursivePass implements RepeatablePassInterface
033 {
034 private $graph;
035 private $currentDefinition;
036 private $onlyConstructorArguments;
037 private $hasProxyDumper;
038 private $lazy;
039 private $expressionLanguage;
040 private $byConstructor;
041
042 /**
043 * @param bool $onlyConstructorArguments Sets this Service Reference pass to ignore method calls
044 */
045 public function __construct($onlyConstructorArguments = false, $hasProxyDumper = true)
046 {
047 $this->onlyConstructorArguments = (bool) $onlyConstructorArguments;
048 $this->hasProxyDumper = (bool) $hasProxyDumper;
049 }
050
051 /**
052 * {@inheritdoc}
053 */
054 public function setRepeatedPass(RepeatedPass $repeatedPass)
055 {
056 // no-op for BC
057 }
058
059 /**
060 * Processes a ContainerBuilder object to populate the service reference graph.
061 */
062 public function process(ContainerBuilder $container)
063 {
064 $this->container = $container;
065 $this->graph = $container->getCompiler()->getServiceReferenceGraph();
066 $this->graph->clear();
067 $this->lazy = false;
068 $this->byConstructor = false;
069
070 foreach ($container->getAliases() as $id => $alias) {
071 $targetId = $this->getDefinitionId((string) $alias);
072 $this->graph->connect($id, $alias, $targetId, $this->getDefinition($targetId), null);
073 }
074
075 parent::process($container);
076 }
077
078 protected function processValue($value, $isRoot = false)
079 {
080 $lazy = $this->lazy;
081
082 if ($value instanceof ArgumentInterface) {
083 $this->lazy = true;
084 parent::processValue($value->getValues());
085 $this->lazy = $lazy;
086
087 return $value;
088 }
089 if ($value instanceof Expression) {
090 $this->getExpressionLanguage()->compile((string) $value, ['this' => 'container']);
091
092 return $value;
093 }
094 if ($value instanceof Reference) {
095 $targetId = $this->getDefinitionId((string) $value);
096 $targetDefinition = $this->getDefinition($targetId);
097
098 $this->graph->connect(
099 $this->currentId,
100 $this->currentDefinition,
101 $targetId,
102 $targetDefinition,
103 $value,
104 $this->lazy || ($this->hasProxyDumper && $targetDefinition && $targetDefinition->isLazy()),
105 ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior(),
106 $this->byConstructor
107 );
108
109 return $value;
110 }
111 if (!$value instanceof Definition) {
112 return parent::processValue($value, $isRoot);
113 }
114 if ($isRoot) {
115 if ($value->isSynthetic() || $value->isAbstract()) {
116 return $value;
117 }
118 $this->currentDefinition = $value;
119 } elseif ($this->currentDefinition === $value) {
120 return $value;
121 }
122 $this->lazy = false;
123
124 $byConstructor = $this->byConstructor;
125 $this->byConstructor = $isRoot || $byConstructor;
126 $this->processValue($value->getFactory());
127 $this->processValue($value->getArguments());
128 $this->byConstructor = $byConstructor;
129
130 if (!$this->onlyConstructorArguments) {
131 $this->processValue($value->getProperties());
132 $this->processValue($value->getMethodCalls());
133 $this->processValue($value->getConfigurator());
134 }
135 $this->lazy = $lazy;
136
137 return $value;
138 }
139
140 /**
141 * Returns a service definition given the full name or an alias.
142 *
143 * @param string $id A full id or alias for a service definition
144 *
145 * @return Definition|null The definition related to the supplied id
146 */
147 private function getDefinition($id)
148 {
149 return null === $id ? null : $this->container->getDefinition($id);
150 }
151
152 private function getDefinitionId($id)
153 {
154 while ($this->container->hasAlias($id)) {
155 $id = (string) $this->container->getAlias($id);
156 }
157
158 if (!$this->container->hasDefinition($id)) {
159 return null;
160 }
161
162 return $this->container->normalizeId($id);
163 }
164
165 private function getExpressionLanguage()
166 {
167 if (null === $this->expressionLanguage) {
168 if (!class_exists(ExpressionLanguage::class)) {
169 throw new RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
170 }
171
172 $providers = $this->container->getExpressionLanguageProviders();
173 $this->expressionLanguage = new ExpressionLanguage(null, $providers, function ($arg) {
174 if ('""' === substr_replace($arg, '', 1, -1)) {
175 $id = stripcslashes(substr($arg, 1, -1));
176 $id = $this->getDefinitionId($id);
177
178 $this->graph->connect(
179 $this->currentId,
180 $this->currentDefinition,
181 $id,
182 $this->getDefinition($id)
183 );
184 }
185
186 return sprintf('$this->get(%s)', $arg);
187 });
188 }
189
190 return $this->expressionLanguage;
191 }
192 }
193