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 |
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\ContainerInterface;
015 use Symfony\Component\DependencyInjection\Definition;
016 use Symfony\Component\DependencyInjection\Reference;
017 use Symfony\Component\DependencyInjection\ContainerBuilder;
018
019 /**
020 * Inline service definitions where this is possible.
021 *
022 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
023 */
024 class InlineServiceDefinitionsPass implements RepeatablePassInterface
025 {
026 private $repeatedPass;
027 private $graph;
028 private $compiler;
029 private $formatter;
030 private $currentId;
031
032 /**
033 * {@inheritdoc}
034 */
035 public function setRepeatedPass(RepeatedPass $repeatedPass)
036 {
037 $this->repeatedPass = $repeatedPass;
038 }
039
040 /**
041 * Processes the ContainerBuilder for inline service definitions.
042 *
043 * @param ContainerBuilder $container
044 */
045 public function process(ContainerBuilder $container)
046 {
047 $this->compiler = $container->getCompiler();
048 $this->formatter = $this->compiler->getLoggingFormatter();
049 $this->graph = $this->compiler->getServiceReferenceGraph();
050
051 $container->setDefinitions($this->inlineArguments($container, $container->getDefinitions(), true));
052 }
053
054 /**
055 * Processes inline arguments.
056 *
057 * @param ContainerBuilder $container The ContainerBuilder
058 * @param array $arguments An array of arguments
059 * @param bool $isRoot If we are processing the root definitions or not
060 *
061 * @return array
062 */
063 private function inlineArguments(ContainerBuilder $container, array $arguments, $isRoot = false)
064 {
065 foreach ($arguments as $k => $argument) {
066 if ($isRoot) {
067 $this->currentId = $k;
068 }
069 if (is_array($argument)) {
070 $arguments[$k] = $this->inlineArguments($container, $argument);
071 } elseif ($argument instanceof Reference) {
072 if (!$container->hasDefinition($id = (string) $argument)) {
073 continue;
074 }
075
076 if ($this->isInlineableDefinition($container, $id, $definition = $container->getDefinition($id))) {
077 $this->compiler->addLogMessage($this->formatter->formatInlineService($this, $id, $this->currentId));
078
079 if ($definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope(false)) {
080 $arguments[$k] = $definition;
081 } else {
082 $arguments[$k] = clone $definition;
083 }
084 }
085 } elseif ($argument instanceof Definition) {
086 $argument->setArguments($this->inlineArguments($container, $argument->getArguments()));
087 $argument->setMethodCalls($this->inlineArguments($container, $argument->getMethodCalls()));
088 $argument->setProperties($this->inlineArguments($container, $argument->getProperties()));
089
090 $configurator = $this->inlineArguments($container, array($argument->getConfigurator()));
091 $argument->setConfigurator($configurator[0]);
092
093 $factory = $this->inlineArguments($container, array($argument->getFactory()));
094 $argument->setFactory($factory[0]);
095 }
096 }
097
098 return $arguments;
099 }
100
101 /**
102 * Checks if the definition is inlineable.
103 *
104 * @param ContainerBuilder $container
105 * @param string $id
106 * @param Definition $definition
107 *
108 * @return bool If the definition is inlineable
109 */
110 private function isInlineableDefinition(ContainerBuilder $container, $id, Definition $definition)
111 {
112 if (!$definition->isShared() || ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope(false)) {
113 return true;
114 }
115
116 if ($definition->isPublic() || $definition->isLazy()) {
117 return false;
118 }
119
120 if (!$this->graph->hasNode($id)) {
121 return true;
122 }
123
124 if ($this->currentId == $id) {
125 return false;
126 }
127
128 $ids = array();
129 foreach ($this->graph->getNode($id)->getInEdges() as $edge) {
130 $ids[] = $edge->getSourceNode()->getId();
131 }
132
133 if (count(array_unique($ids)) > 1) {
134 return false;
135 }
136
137 if (count($ids) > 1 && is_array($factory = $definition->getFactory()) && ($factory[0] instanceof Reference || $factory[0] instanceof Definition)) {
138 return false;
139 }
140
141 if (count($ids) > 1 && $definition->getFactoryService(false)) {
142 return false;
143 }
144
145 return $container->getDefinition(reset($ids))->getScope(false) === $definition->getScope(false);
146 }
147 }
148