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 |
AbstractRecursivePass.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\Definition;
017 use Symfony\Component\DependencyInjection\Exception\RuntimeException;
018 use Symfony\Component\DependencyInjection\Reference;
019
020 /**
021 * @author Nicolas Grekas <p@tchwork.com>
022 */
023 abstract class AbstractRecursivePass implements CompilerPassInterface
024 {
025 /**
026 * @var ContainerBuilder
027 */
028 protected $container;
029 protected $currentId;
030
031 /**
032 * {@inheritdoc}
033 */
034 public function process(ContainerBuilder $container)
035 {
036 $this->container = $container;
037
038 try {
039 $this->processValue($container->getDefinitions(), true);
040 } finally {
041 $this->container = null;
042 }
043 }
044
045 /**
046 * Processes a value found in a definition tree.
047 *
048 * @param mixed $value
049 * @param bool $isRoot
050 *
051 * @return mixed The processed value
052 */
053 protected function processValue($value, $isRoot = false)
054 {
055 if (\is_array($value)) {
056 foreach ($value as $k => $v) {
057 if ($isRoot) {
058 $this->currentId = $k;
059 }
060 if ($v !== $processedValue = $this->processValue($v, $isRoot)) {
061 $value[$k] = $processedValue;
062 }
063 }
064 } elseif ($value instanceof ArgumentInterface) {
065 $value->setValues($this->processValue($value->getValues()));
066 } elseif ($value instanceof Definition) {
067 $value->setArguments($this->processValue($value->getArguments()));
068 $value->setProperties($this->processValue($value->getProperties()));
069 $value->setMethodCalls($this->processValue($value->getMethodCalls()));
070
071 $changes = $value->getChanges();
072 if (isset($changes['factory'])) {
073 $value->setFactory($this->processValue($value->getFactory()));
074 }
075 if (isset($changes['configurator'])) {
076 $value->setConfigurator($this->processValue($value->getConfigurator()));
077 }
078 }
079
080 return $value;
081 }
082
083 /**
084 * @param bool $required
085 *
086 * @return \ReflectionFunctionAbstract|null
087 *
088 * @throws RuntimeException
089 */
090 protected function getConstructor(Definition $definition, $required)
091 {
092 if ($definition->isSynthetic()) {
093 return null;
094 }
095
096 if (\is_string($factory = $definition->getFactory())) {
097 if (!\function_exists($factory)) {
098 throw new RuntimeException(sprintf('Invalid service "%s": function "%s" does not exist.', $this->currentId, $factory));
099 }
100 $r = new \ReflectionFunction($factory);
101 if (false !== $r->getFileName() && file_exists($r->getFileName())) {
102 $this->container->fileExists($r->getFileName());
103 }
104
105 return $r;
106 }
107
108 if ($factory) {
109 list($class, $method) = $factory;
110 if ($class instanceof Reference) {
111 $class = $this->container->findDefinition((string) $class)->getClass();
112 } elseif (null === $class) {
113 $class = $definition->getClass();
114 }
115 if ('__construct' === $method) {
116 throw new RuntimeException(sprintf('Invalid service "%s": "__construct()" cannot be used as a factory method.', $this->currentId));
117 }
118
119 return $this->getReflectionMethod(new Definition($class), $method);
120 }
121
122 $class = $definition->getClass();
123
124 try {
125 if (!$r = $this->container->getReflectionClass($class)) {
126 throw new RuntimeException(sprintf('Invalid service "%s": class "%s" does not exist.', $this->currentId, $class));
127 }
128 } catch (\ReflectionException $e) {
129 throw new RuntimeException(sprintf('Invalid service "%s": ', $this->currentId).lcfirst($e->getMessage()));
130 }
131 if (!$r = $r->getConstructor()) {
132 if ($required) {
133 throw new RuntimeException(sprintf('Invalid service "%s": class%s has no constructor.', $this->currentId, sprintf($class !== $this->currentId ? ' "%s"' : '', $class)));
134 }
135 } elseif (!$r->isPublic()) {
136 throw new RuntimeException(sprintf('Invalid service "%s": ', $this->currentId).sprintf($class !== $this->currentId ? 'constructor of class "%s"' : 'its constructor', $class).' must be public.');
137 }
138
139 return $r;
140 }
141
142 /**
143 * @param string $method
144 *
145 * @throws RuntimeException
146 *
147 * @return \ReflectionFunctionAbstract
148 */
149 protected function getReflectionMethod(Definition $definition, $method)
150 {
151 if ('__construct' === $method) {
152 return $this->getConstructor($definition, true);
153 }
154
155 if (!$class = $definition->getClass()) {
156 throw new RuntimeException(sprintf('Invalid service "%s": the class is not set.', $this->currentId));
157 }
158
159 if (!$r = $this->container->getReflectionClass($class)) {
160 throw new RuntimeException(sprintf('Invalid service "%s": class "%s" does not exist.', $this->currentId, $class));
161 }
162
163 if (!$r->hasMethod($method)) {
164 throw new RuntimeException(sprintf('Invalid service "%s": method "%s()" does not exist.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method));
165 }
166
167 $r = $r->getMethod($method);
168 if (!$r->isPublic()) {
169 throw new RuntimeException(sprintf('Invalid service "%s": method "%s()" must be public.', $this->currentId, $class !== $this->currentId ? $class.'::'.$method : $method));
170 }
171
172 return $r;
173 }
174 }
175