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 |
InlineServiceDefinitionsPass.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\Definition;
016 use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
017 use Symfony\Component\DependencyInjection\Reference;
018
019 /**
020 * Inline service definitions where this is possible.
021 *
022 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
023 */
024 class InlineServiceDefinitionsPass extends AbstractRecursivePass implements RepeatablePassInterface
025 {
026 private $cloningIds = [];
027 private $inlinedServiceIds = [];
028
029 /**
030 * {@inheritdoc}
031 */
032 public function setRepeatedPass(RepeatedPass $repeatedPass)
033 {
034 // no-op for BC
035 }
036
037 /**
038 * Returns an array of all services inlined by this pass.
039 *
040 * The key is the inlined service id and its value is the list of services it was inlined into.
041 *
042 * @deprecated since version 3.4, to be removed in 4.0.
043 *
044 * @return array
045 */
046 public function getInlinedServiceIds()
047 {
048 @trigger_error('Calling InlineServiceDefinitionsPass::getInlinedServiceIds() is deprecated since Symfony 3.4 and will be removed in 4.0.', \E_USER_DEPRECATED);
049
050 return $this->inlinedServiceIds;
051 }
052
053 /**
054 * {@inheritdoc}
055 */
056 protected function processValue($value, $isRoot = false)
057 {
058 if ($value instanceof ArgumentInterface) {
059 // Reference found in ArgumentInterface::getValues() are not inlineable
060 return $value;
061 }
062
063 if ($value instanceof Definition && $this->cloningIds) {
064 if ($value->isShared()) {
065 return $value;
066 }
067 $value = clone $value;
068 }
069
070 if (!$value instanceof Reference || !$this->container->hasDefinition($id = $this->container->normalizeId($value))) {
071 return parent::processValue($value, $isRoot);
072 }
073
074 $definition = $this->container->getDefinition($id);
075
076 if (!$this->isInlineableDefinition($id, $definition, $this->container->getCompiler()->getServiceReferenceGraph())) {
077 return $value;
078 }
079
080 $this->container->log($this, sprintf('Inlined service "%s" to "%s".', $id, $this->currentId));
081 $this->inlinedServiceIds[$id][] = $this->currentId;
082
083 if ($definition->isShared()) {
084 return $definition;
085 }
086
087 if (isset($this->cloningIds[$id])) {
088 $ids = array_keys($this->cloningIds);
089 $ids[] = $id;
090
091 throw new ServiceCircularReferenceException($id, \array_slice($ids, array_search($id, $ids)));
092 }
093
094 $this->cloningIds[$id] = true;
095 try {
096 return $this->processValue($definition);
097 } finally {
098 unset($this->cloningIds[$id]);
099 }
100 }
101
102 /**
103 * Checks if the definition is inlineable.
104 *
105 * @return bool If the definition is inlineable
106 */
107 private function isInlineableDefinition($id, Definition $definition, ServiceReferenceGraph $graph)
108 {
109 if ($definition->getErrors() || $definition->isDeprecated() || $definition->isLazy() || $definition->isSynthetic()) {
110 return false;
111 }
112
113 if (!$definition->isShared()) {
114 return true;
115 }
116
117 if ($definition->isPublic() || $definition->isPrivate()) {
118 return false;
119 }
120
121 if (!$graph->hasNode($id)) {
122 return true;
123 }
124
125 if ($this->currentId == $id) {
126 return false;
127 }
128
129 $ids = [];
130 $isReferencedByConstructor = false;
131 foreach ($graph->getNode($id)->getInEdges() as $edge) {
132 $isReferencedByConstructor = $isReferencedByConstructor || $edge->isReferencedByConstructor();
133 if ($edge->isWeak() || $edge->isLazy()) {
134 return false;
135 }
136 $ids[] = $edge->getSourceNode()->getId();
137 }
138
139 if (!$ids) {
140 return true;
141 }
142
143 if (\count(array_unique($ids)) > 1) {
144 return false;
145 }
146
147 if (\count($ids) > 1 && \is_array($factory = $definition->getFactory()) && ($factory[0] instanceof Reference || $factory[0] instanceof Definition)) {
148 return false;
149 }
150
151 return $this->container->getDefinition($ids[0])->isShared();
152 }
153 }
154