@@ -54,19 +54,19 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function make(string $alias, array $parameters = [], string $context = null): mixed |
56 | 56 | { |
57 | - if (!isset($this->state->bindings[$alias])) { |
|
57 | + if (!isset($this->state->bindings[$alias])){ |
|
58 | 58 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
59 | - try { |
|
59 | + try{ |
|
60 | 60 | //No direct instructions how to construct class, make is automatically |
61 | 61 | return $this->autowire($alias, $parameters, $context); |
62 | - } finally { |
|
62 | + }finally{ |
|
63 | 63 | $this->tracer->pop(false); |
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
67 | 67 | $avoidCache = $parameters !== []; |
68 | 68 | $binding = $this->state->bindings[$alias]; |
69 | - try { |
|
69 | + try{ |
|
70 | 70 | $this->tracer->push( |
71 | 71 | false, |
72 | 72 | action: 'resolve from binding', |
@@ -76,23 +76,23 @@ discard block |
||
76 | 76 | ); |
77 | 77 | $this->tracer->push(true); |
78 | 78 | |
79 | - if (\is_object($binding)) { |
|
80 | - if ($binding::class === WeakReference::class) { |
|
81 | - if (($avoidCache || $binding->get() === null) && \class_exists($alias)) { |
|
82 | - try { |
|
79 | + if (\is_object($binding)){ |
|
80 | + if ($binding::class === WeakReference::class){ |
|
81 | + if (($avoidCache || $binding->get() === null) && \class_exists($alias)){ |
|
82 | + try{ |
|
83 | 83 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
84 | 84 | $object = $this->createInstance($alias, $parameters, $context); |
85 | - if ($avoidCache) { |
|
85 | + if ($avoidCache){ |
|
86 | 86 | return $object; |
87 | 87 | } |
88 | 88 | $binding = $this->state->bindings[$alias] = WeakReference::create($object); |
89 | - } catch (\Throwable) { |
|
89 | + }catch (\Throwable){ |
|
90 | 90 | throw new ContainerException($this->tracer->combineTraceMessage(\sprintf( |
91 | 91 | 'Can\'t resolve `%s`: can\'t instantiate `%s` from WeakReference binding.', |
92 | 92 | $this->tracer->getRootAlias(), |
93 | 93 | $alias, |
94 | 94 | ))); |
95 | - } finally { |
|
95 | + }finally{ |
|
96 | 96 | $this->tracer->pop(); |
97 | 97 | } |
98 | 98 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | : $binding; |
105 | 105 | } |
106 | 106 | |
107 | - if (\is_string($binding)) { |
|
107 | + if (\is_string($binding)){ |
|
108 | 108 | return $binding === $alias |
109 | 109 | ? $this->autowire($alias, $parameters, $context) |
110 | 110 | //Binding is pointing to something else |
@@ -112,20 +112,20 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 114 | unset($this->state->bindings[$alias]); |
115 | - try { |
|
115 | + try{ |
|
116 | 116 | $instance = $binding[0] === $alias |
117 | 117 | ? $this->autowire($alias, $parameters, $context) |
118 | 118 | : $this->evaluateBinding($alias, $binding[0], $parameters, $context); |
119 | - } finally { |
|
119 | + }finally{ |
|
120 | 120 | /** @psalm-var class-string $alias */ |
121 | 121 | $this->state->bindings[$alias] = $binding; |
122 | 122 | } |
123 | - } finally { |
|
123 | + }finally{ |
|
124 | 124 | $this->tracer->pop(true); |
125 | 125 | $this->tracer->pop(false); |
126 | 126 | } |
127 | 127 | |
128 | - if ($binding[1]) { |
|
128 | + if ($binding[1]){ |
|
129 | 129 | // Indicates singleton |
130 | 130 | /** @psalm-var class-string $alias */ |
131 | 131 | $this->state->bindings[$alias] = $instance; |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | && |
151 | 151 | (isset($this->state->injectors[$class]) || $this->binder->hasInjector($class)) |
152 | 152 | )) |
153 | - ) { |
|
153 | + ){ |
|
154 | 154 | throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf( |
155 | 155 | 'Can\'t resolve `%s`: undefined class or binding `%s`.', |
156 | 156 | $this->tracer->getRootAlias(), |
@@ -179,18 +179,18 @@ discard block |
||
179 | 179 | array $parameters, |
180 | 180 | string $context = null |
181 | 181 | ): mixed { |
182 | - if (\is_string($target)) { |
|
182 | + if (\is_string($target)){ |
|
183 | 183 | // Reference |
184 | 184 | return $this->make($target, $parameters, $context); |
185 | 185 | } |
186 | 186 | |
187 | - if ($target instanceof Autowire) { |
|
187 | + if ($target instanceof Autowire){ |
|
188 | 188 | return $target->resolve($this, $parameters); |
189 | 189 | } |
190 | 190 | |
191 | - try { |
|
191 | + try{ |
|
192 | 192 | return $this->invoker->invoke($target, $parameters); |
193 | - } catch (NotCallableException $e) { |
|
193 | + }catch (NotCallableException $e){ |
|
194 | 194 | throw new ContainerException( |
195 | 195 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $alias)), |
196 | 196 | $e->getCode(), |
@@ -214,20 +214,20 @@ discard block |
||
214 | 214 | */ |
215 | 215 | private function createInstance(string $class, array $parameters, string $context = null): object |
216 | 216 | { |
217 | - try { |
|
217 | + try{ |
|
218 | 218 | $reflection = new \ReflectionClass($class); |
219 | - } catch (\ReflectionException $e) { |
|
219 | + }catch (\ReflectionException $e){ |
|
220 | 220 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
221 | 221 | } |
222 | 222 | |
223 | 223 | //We have to construct class using external injector when we know exact context |
224 | - if ($parameters === [] && $this->binder->hasInjector($class)) { |
|
224 | + if ($parameters === [] && $this->binder->hasInjector($class)){ |
|
225 | 225 | $injector = $this->state->injectors[$reflection->getName()]; |
226 | 226 | |
227 | - try { |
|
227 | + try{ |
|
228 | 228 | $injectorInstance = $this->container->get($injector); |
229 | 229 | |
230 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
230 | + if (!$injectorInstance instanceof InjectorInterface){ |
|
231 | 231 | throw new InjectionException( |
232 | 232 | \sprintf( |
233 | 233 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | * @psalm-suppress RedundantCondition |
243 | 243 | */ |
244 | 244 | $instance = $injectorInstance->createInjection($reflection, $context); |
245 | - if (!$reflection->isInstance($instance)) { |
|
245 | + if (!$reflection->isInstance($instance)){ |
|
246 | 246 | throw new InjectionException( |
247 | 247 | \sprintf( |
248 | 248 | "Invalid injection response for '%s'.", |
@@ -252,12 +252,12 @@ discard block |
||
252 | 252 | } |
253 | 253 | |
254 | 254 | return $instance; |
255 | - } finally { |
|
255 | + }finally{ |
|
256 | 256 | $this->state->injectors[$reflection->getName()] = $injector; |
257 | 257 | } |
258 | 258 | } |
259 | 259 | |
260 | - if (!$reflection->isInstantiable()) { |
|
260 | + if (!$reflection->isInstantiable()){ |
|
261 | 261 | $itIs = match (true) { |
262 | 262 | $reflection->isEnum() => 'Enum', |
263 | 263 | $reflection->isAbstract() => 'Abstract class', |
@@ -270,12 +270,12 @@ discard block |
||
270 | 270 | |
271 | 271 | $constructor = $reflection->getConstructor(); |
272 | 272 | |
273 | - if ($constructor !== null) { |
|
274 | - try { |
|
273 | + if ($constructor !== null){ |
|
274 | + try{ |
|
275 | 275 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
276 | 276 | $this->tracer->push(true); |
277 | 277 | $arguments = $this->resolver->resolveArguments($constructor, $parameters); |
278 | - } catch (ValidationException $e) { |
|
278 | + }catch (ValidationException $e){ |
|
279 | 279 | throw new ContainerException( |
280 | 280 | $this->tracer->combineTraceMessage( |
281 | 281 | \sprintf( |
@@ -285,22 +285,22 @@ discard block |
||
285 | 285 | ) |
286 | 286 | ), |
287 | 287 | ); |
288 | - } finally { |
|
288 | + }finally{ |
|
289 | 289 | $this->tracer->pop(true); |
290 | 290 | $this->tracer->pop(false); |
291 | 291 | } |
292 | - try { |
|
292 | + try{ |
|
293 | 293 | // Using constructor with resolved arguments |
294 | 294 | $this->tracer->push(false, call: "$class::__construct", arguments: $arguments); |
295 | 295 | $this->tracer->push(true); |
296 | 296 | $instance = new $class(...$arguments); |
297 | - } catch (\TypeError $e) { |
|
297 | + }catch (\TypeError $e){ |
|
298 | 298 | throw new WrongTypeException($constructor, $e); |
299 | - } finally { |
|
299 | + }finally{ |
|
300 | 300 | $this->tracer->pop(true); |
301 | 301 | $this->tracer->pop(false); |
302 | 302 | } |
303 | - } else { |
|
303 | + }else{ |
|
304 | 304 | // No constructor specified |
305 | 305 | $instance = $reflection->newInstance(); |
306 | 306 | } |
@@ -321,9 +321,9 @@ discard block |
||
321 | 321 | private function registerInstance(object $instance): object |
322 | 322 | { |
323 | 323 | //Declarative singletons |
324 | - if ($instance instanceof SingletonInterface) { |
|
324 | + if ($instance instanceof SingletonInterface){ |
|
325 | 325 | $alias = $instance::class; |
326 | - if (!isset($this->state->bindings[$alias])) { |
|
326 | + if (!isset($this->state->bindings[$alias])){ |
|
327 | 327 | $this->state->bindings[$alias] = $instance; |
328 | 328 | } |
329 | 329 | } |