1 | <?php |
||
20 | class ServiceDefinition |
||
21 | { |
||
22 | /** |
||
23 | * @var Reader |
||
24 | */ |
||
25 | protected $reader; |
||
26 | |||
27 | /** |
||
28 | * @var ContainerBuilder |
||
29 | */ |
||
30 | protected $container; |
||
31 | |||
32 | /** |
||
33 | * @param ContainerBuilder $container |
||
34 | * @param Reader $reader |
||
35 | */ |
||
36 | 1 | public function __construct(ContainerBuilder $container, Reader $reader) |
|
41 | |||
42 | /** |
||
43 | * @param ReflectionClass $reflectionClass |
||
44 | * @param Service $annotation |
||
45 | * @param Definition $definition |
||
46 | * @return array |
||
47 | */ |
||
48 | 1 | public function build(ReflectionClass $reflectionClass, Service $annotation, Definition $definition) |
|
63 | |||
64 | /** |
||
65 | * @param Definition $definition |
||
66 | * @param string $serviceId |
||
67 | * @return string null |
||
68 | */ |
||
69 | 1 | public function setupDefinition(Definition $definition, string $serviceId) |
|
73 | |||
74 | /** |
||
75 | * @param string|string[] $value |
||
76 | * @return Reference[]|Reference|Expression |
||
77 | */ |
||
78 | 1 | private function resolveServices($value) |
|
90 | |||
91 | /** |
||
92 | * @param ReflectionMethod $constructor |
||
93 | * @param Definition $definition |
||
94 | */ |
||
95 | 1 | protected function processConstructor(ReflectionMethod $constructor, Definition $definition) |
|
96 | { |
||
97 | 1 | if ($annotation = $this->reader->getMethodAnnotation($constructor, Inject::class)) { |
|
98 | /** @var Inject $annotation */ |
||
99 | 1 | $arguments = $this->extractArguments( |
|
100 | 1 | $constructor, |
|
101 | 1 | $annotation, |
|
102 | 1 | $definition->getArguments() |
|
103 | ); |
||
104 | |||
105 | 1 | $definition->setArguments($arguments); |
|
106 | 1 | } elseif ($constructor->getNumberOfParameters() > 0) { |
|
107 | 1 | $definition->setArguments( |
|
108 | 1 | $this->resolveArguments($constructor) |
|
109 | ); |
||
110 | |||
111 | 1 | $definition->setAutowired(true); |
|
112 | } |
||
113 | 1 | } |
|
114 | |||
115 | /** |
||
116 | * @param ReflectionMethod[] $methods |
||
117 | * @param Definition $definition |
||
118 | */ |
||
119 | 1 | protected function processMethods(array $methods, Definition $definition) : void |
|
128 | |||
129 | /** |
||
130 | * @param ReflectionMethod $method |
||
131 | * @param Inject $annotation |
||
132 | * @param array $arguments |
||
133 | * @return array |
||
134 | */ |
||
135 | 1 | private function extractArguments( |
|
149 | |||
150 | /** |
||
151 | * @param ReflectionMethod $method |
||
152 | * @param array $values |
||
153 | * @param array $arguments |
||
154 | * @return array |
||
155 | */ |
||
156 | 1 | private function resolveArguments( |
|
177 | |||
178 | /** |
||
179 | * @param Service $annotation |
||
180 | * @param Definition $definition |
||
181 | */ |
||
182 | 1 | private function processService(Service $annotation, Definition $definition) : void |
|
183 | { |
||
184 | 1 | $definition->setAutowired(true); |
|
185 | 1 | $definition->setPublic($annotation->public); |
|
186 | 1 | $definition->setLazy($annotation->lazy); |
|
187 | 1 | $definition->setShared($annotation->shared); |
|
188 | 1 | $definition->setSynthetic($annotation->synthetic); |
|
189 | 1 | $definition->setAbstract($annotation->abstract); |
|
190 | 1 | $this->processConfigurator($annotation, $definition); |
|
191 | |||
192 | 1 | if (null === $annotation->factory) { |
|
193 | 1 | $definition->setFactory($annotation->factory); |
|
194 | } |
||
195 | 1 | } |
|
196 | |||
197 | /** |
||
198 | * @param ReflectionClass $reflectionClass |
||
199 | * @param Service $annotation |
||
200 | * @param Definition $definition |
||
201 | */ |
||
202 | 1 | private function processTags( |
|
203 | ReflectionClass $reflectionClass, |
||
204 | Service $annotation, |
||
205 | Definition $definition |
||
206 | ) { |
||
207 | 1 | if (empty($annotation->tags)) { |
|
208 | 1 | return; |
|
209 | } |
||
210 | |||
211 | 1 | foreach ($annotation->tags as $tag) { |
|
212 | 1 | if (!isset($tag['name'])) { |
|
213 | throw new InvalidArgumentException( |
||
214 | sprintf( |
||
215 | 'A "tags" entry is missing a "name" key must be an array for class "%s" in %s.', |
||
216 | $reflectionClass->getName(), |
||
217 | $reflectionClass->getFileName() |
||
218 | ) |
||
219 | ); |
||
220 | } |
||
221 | 1 | $name = $tag['name']; |
|
222 | 1 | unset($tag['name']); |
|
223 | |||
224 | 1 | $definition->addTag($name, $tag); |
|
225 | } |
||
226 | 1 | } |
|
227 | |||
228 | /** |
||
229 | * @param string $value |
||
230 | * @return Reference |
||
231 | */ |
||
232 | 1 | private function getValueReference(string $value) : Reference |
|
252 | |||
253 | /** |
||
254 | * @param Service $annotation |
||
255 | * @param Definition $definition |
||
256 | */ |
||
257 | 1 | private function processConfigurator(Service $annotation, Definition $definition) : void |
|
272 | |||
273 | /** |
||
274 | * @param Definition $definition |
||
275 | * @param ReflectionMethod $method |
||
276 | */ |
||
277 | 1 | protected function processMethod(Definition $definition, ReflectionMethod $method) : void |
|
289 | } |
||
290 |
This check looks
TODO
comments that have been left in the code.``TODO``s show that something is left unfinished and should be attended to.