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 |
ResolveChildDefinitionsPass.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\ChildDefinition;
015 use Symfony\Component\DependencyInjection\Definition;
016 use Symfony\Component\DependencyInjection\Exception\ExceptionInterface;
017 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
018 use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
019
020 /**
021 * This replaces all ChildDefinition instances with their equivalent fully
022 * merged Definition instance.
023 *
024 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
025 * @author Nicolas Grekas <p@tchwork.com>
026 */
027 class ResolveChildDefinitionsPass extends AbstractRecursivePass
028 {
029 private $currentPath;
030
031 protected function processValue($value, $isRoot = false)
032 {
033 if (!$value instanceof Definition) {
034 return parent::processValue($value, $isRoot);
035 }
036 if ($isRoot) {
037 // yes, we are specifically fetching the definition from the
038 // container to ensure we are not operating on stale data
039 $value = $this->container->getDefinition($this->currentId);
040 }
041 if ($value instanceof ChildDefinition) {
042 $this->currentPath = [];
043 $value = $this->resolveDefinition($value);
044 if ($isRoot) {
045 $this->container->setDefinition($this->currentId, $value);
046 }
047 }
048
049 return parent::processValue($value, $isRoot);
050 }
051
052 /**
053 * Resolves the definition.
054 *
055 * @return Definition
056 *
057 * @throws RuntimeException When the definition is invalid
058 */
059 private function resolveDefinition(ChildDefinition $definition)
060 {
061 try {
062 return $this->doResolveDefinition($definition);
063 } catch (ServiceCircularReferenceException $e) {
064 throw $e;
065 } catch (ExceptionInterface $e) {
066 $r = new \ReflectionProperty($e, 'message');
067 $r->setAccessible(true);
068 $r->setValue($e, sprintf('Service "%s": %s', $this->currentId, $e->getMessage()));
069
070 throw $e;
071 }
072 }
073
074 private function doResolveDefinition(ChildDefinition $definition)
075 {
076 if (!$this->container->has($parent = $definition->getParent())) {
077 throw new RuntimeException(sprintf('Parent definition "%s" does not exist.', $parent));
078 }
079
080 $searchKey = array_search($parent, $this->currentPath);
081 $this->currentPath[] = $parent;
082
083 if (false !== $searchKey) {
084 throw new ServiceCircularReferenceException($parent, \array_slice($this->currentPath, $searchKey));
085 }
086
087 $parentDef = $this->container->findDefinition($parent);
088 if ($parentDef instanceof ChildDefinition) {
089 $id = $this->currentId;
090 $this->currentId = $parent;
091 $parentDef = $this->resolveDefinition($parentDef);
092 $this->container->setDefinition($parent, $parentDef);
093 $this->currentId = $id;
094 }
095
096 $this->container->log($this, sprintf('Resolving inheritance for "%s" (parent: %s).', $this->currentId, $parent));
097 $def = new Definition();
098
099 // merge in parent definition
100 // purposely ignored attributes: abstract, shared, tags, autoconfigured
101 $def->setClass($parentDef->getClass());
102 $def->setArguments($parentDef->getArguments());
103 $def->setMethodCalls($parentDef->getMethodCalls());
104 $def->setProperties($parentDef->getProperties());
105 if ($parentDef->getAutowiringTypes(false)) {
106 $def->setAutowiringTypes($parentDef->getAutowiringTypes(false));
107 }
108 if ($parentDef->isDeprecated()) {
109 $def->setDeprecated(true, $parentDef->getDeprecationMessage('%service_id%'));
110 }
111 $def->setFactory($parentDef->getFactory());
112 $def->setConfigurator($parentDef->getConfigurator());
113 $def->setFile($parentDef->getFile());
114 $def->setPublic($parentDef->isPublic());
115 $def->setLazy($parentDef->isLazy());
116 $def->setAutowired($parentDef->isAutowired());
117 $def->setChanges($parentDef->getChanges());
118
119 $def->setBindings($definition->getBindings() + $parentDef->getBindings());
120
121 // overwrite with values specified in the decorator
122 $changes = $definition->getChanges();
123 if (isset($changes['class'])) {
124 $def->setClass($definition->getClass());
125 }
126 if (isset($changes['factory'])) {
127 $def->setFactory($definition->getFactory());
128 }
129 if (isset($changes['configurator'])) {
130 $def->setConfigurator($definition->getConfigurator());
131 }
132 if (isset($changes['file'])) {
133 $def->setFile($definition->getFile());
134 }
135 if (isset($changes['public'])) {
136 $def->setPublic($definition->isPublic());
137 } else {
138 $def->setPrivate($definition->isPrivate() || $parentDef->isPrivate());
139 }
140 if (isset($changes['lazy'])) {
141 $def->setLazy($definition->isLazy());
142 }
143 if (isset($changes['deprecated'])) {
144 $def->setDeprecated($definition->isDeprecated(), $definition->getDeprecationMessage('%service_id%'));
145 }
146 if (isset($changes['autowired'])) {
147 $def->setAutowired($definition->isAutowired());
148 }
149 if (isset($changes['shared'])) {
150 $def->setShared($definition->isShared());
151 }
152 if (isset($changes['decorated_service'])) {
153 $decoratedService = $definition->getDecoratedService();
154 if (null === $decoratedService) {
155 $def->setDecoratedService($decoratedService);
156 } else {
157 $def->setDecoratedService($decoratedService[0], $decoratedService[1], $decoratedService[2]);
158 }
159 }
160
161 // merge arguments
162 foreach ($definition->getArguments() as $k => $v) {
163 if (is_numeric($k)) {
164 $def->addArgument($v);
165 } elseif (0 === strpos($k, 'index_')) {
166 $def->replaceArgument((int) substr($k, \strlen('index_')), $v);
167 } else {
168 $def->setArgument($k, $v);
169 }
170 }
171
172 // merge properties
173 foreach ($definition->getProperties() as $k => $v) {
174 $def->setProperty($k, $v);
175 }
176
177 // append method calls
178 if ($calls = $definition->getMethodCalls()) {
179 $def->setMethodCalls(array_merge($def->getMethodCalls(), $calls));
180 }
181
182 // merge autowiring types
183 foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
184 $def->addAutowiringType($autowiringType);
185 }
186
187 // these attributes are always taken from the child
188 $def->setAbstract($definition->isAbstract());
189 $def->setTags($definition->getTags());
190 // autoconfigure is never taken from parent (on purpose)
191 // and it's not legal on an instanceof
192 $def->setAutoconfigured($definition->isAutoconfigured());
193
194 return $def;
195 }
196 }
197
198 class_alias(ResolveChildDefinitionsPass::class, ResolveDefinitionTemplatesPass::class);
199