@@ -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,26 +104,26 @@ discard block |
||
104 | 104 | : $binding; |
105 | 105 | } |
106 | 106 | |
107 | - if (\is_string($binding)) { |
|
107 | + if (\is_string($binding)){ |
|
108 | 108 | //Binding is pointing to something else |
109 | 109 | return $this->make($binding, $parameters, $context); |
110 | 110 | } |
111 | 111 | |
112 | 112 | unset($this->state->bindings[$alias]); |
113 | - try { |
|
113 | + try{ |
|
114 | 114 | $instance = $binding[0] === $alias |
115 | 115 | ? $this->autowire($alias, $parameters, $context) |
116 | 116 | : $this->evaluateBinding($alias, $binding[0], $parameters, $context); |
117 | - } finally { |
|
117 | + }finally{ |
|
118 | 118 | /** @psalm-var class-string $alias */ |
119 | 119 | $this->state->bindings[$alias] = $binding; |
120 | 120 | } |
121 | - } finally { |
|
121 | + }finally{ |
|
122 | 122 | $this->tracer->pop(true); |
123 | 123 | $this->tracer->pop(false); |
124 | 124 | } |
125 | 125 | |
126 | - if ($binding[1]) { |
|
126 | + if ($binding[1]){ |
|
127 | 127 | // Indicates singleton |
128 | 128 | /** @psalm-var class-string $alias */ |
129 | 129 | $this->state->bindings[$alias] = $instance; |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | && |
149 | 149 | (isset($this->state->injectors[$class]) || $this->binder->hasInjector($class)) |
150 | 150 | )) |
151 | - ) { |
|
151 | + ){ |
|
152 | 152 | throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf( |
153 | 153 | 'Can\'t resolve `%s`: undefined class or binding `%s`.', |
154 | 154 | $this->tracer->getRootAlias(), |
@@ -177,18 +177,18 @@ discard block |
||
177 | 177 | array $parameters, |
178 | 178 | string $context = null |
179 | 179 | ): mixed { |
180 | - if (\is_string($target)) { |
|
180 | + if (\is_string($target)){ |
|
181 | 181 | // Reference |
182 | 182 | return $this->make($target, $parameters, $context); |
183 | 183 | } |
184 | 184 | |
185 | - if ($target instanceof Autowire) { |
|
185 | + if ($target instanceof Autowire){ |
|
186 | 186 | return $target->resolve($this, $parameters); |
187 | 187 | } |
188 | 188 | |
189 | - try { |
|
189 | + try{ |
|
190 | 190 | return $this->invoker->invoke($target, $parameters); |
191 | - } catch (NotCallableException $e) { |
|
191 | + }catch (NotCallableException $e){ |
|
192 | 192 | throw new ContainerException( |
193 | 193 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $alias)), |
194 | 194 | $e->getCode(), |
@@ -212,20 +212,20 @@ discard block |
||
212 | 212 | */ |
213 | 213 | private function createInstance(string $class, array $parameters, string $context = null): object |
214 | 214 | { |
215 | - try { |
|
215 | + try{ |
|
216 | 216 | $reflection = new \ReflectionClass($class); |
217 | - } catch (\ReflectionException $e) { |
|
217 | + }catch (\ReflectionException $e){ |
|
218 | 218 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
219 | 219 | } |
220 | 220 | |
221 | 221 | //We have to construct class using external injector when we know exact context |
222 | - if ($parameters === [] && $this->binder->hasInjector($class)) { |
|
222 | + if ($parameters === [] && $this->binder->hasInjector($class)){ |
|
223 | 223 | $injector = $this->state->injectors[$reflection->getName()]; |
224 | 224 | |
225 | - try { |
|
225 | + try{ |
|
226 | 226 | $injectorInstance = $this->container->get($injector); |
227 | 227 | |
228 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
228 | + if (!$injectorInstance instanceof InjectorInterface){ |
|
229 | 229 | throw new InjectionException( |
230 | 230 | \sprintf( |
231 | 231 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | |
238 | 238 | /** @var InjectorInterface<TObject> $injectorInstance */ |
239 | 239 | $instance = $injectorInstance->createInjection($reflection, $context); |
240 | - if (!$reflection->isInstance($instance)) { |
|
240 | + if (!$reflection->isInstance($instance)){ |
|
241 | 241 | throw new InjectionException( |
242 | 242 | \sprintf( |
243 | 243 | "Invalid injection response for '%s'.", |
@@ -247,12 +247,12 @@ discard block |
||
247 | 247 | } |
248 | 248 | |
249 | 249 | return $instance; |
250 | - } finally { |
|
250 | + }finally{ |
|
251 | 251 | $this->state->injectors[$reflection->getName()] = $injector; |
252 | 252 | } |
253 | 253 | } |
254 | 254 | |
255 | - if (!$reflection->isInstantiable()) { |
|
255 | + if (!$reflection->isInstantiable()){ |
|
256 | 256 | $itIs = match (true) { |
257 | 257 | $reflection->isEnum() => 'Enum', |
258 | 258 | $reflection->isAbstract() => 'Abstract class', |
@@ -265,12 +265,12 @@ discard block |
||
265 | 265 | |
266 | 266 | $constructor = $reflection->getConstructor(); |
267 | 267 | |
268 | - if ($constructor !== null) { |
|
269 | - try { |
|
268 | + if ($constructor !== null){ |
|
269 | + try{ |
|
270 | 270 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
271 | 271 | $this->tracer->push(true); |
272 | 272 | $arguments = $this->resolver->resolveArguments($constructor, $parameters); |
273 | - } catch (ValidationException $e) { |
|
273 | + }catch (ValidationException $e){ |
|
274 | 274 | throw new ContainerException( |
275 | 275 | $this->tracer->combineTraceMessage( |
276 | 276 | \sprintf( |
@@ -280,22 +280,22 @@ discard block |
||
280 | 280 | ) |
281 | 281 | ), |
282 | 282 | ); |
283 | - } finally { |
|
283 | + }finally{ |
|
284 | 284 | $this->tracer->pop(true); |
285 | 285 | $this->tracer->pop(false); |
286 | 286 | } |
287 | - try { |
|
287 | + try{ |
|
288 | 288 | // Using constructor with resolved arguments |
289 | 289 | $this->tracer->push(false, call: "$class::__construct", arguments: $arguments); |
290 | 290 | $this->tracer->push(true); |
291 | 291 | $instance = new $class(...$arguments); |
292 | - } catch (\TypeError $e) { |
|
292 | + }catch (\TypeError $e){ |
|
293 | 293 | throw new WrongTypeException($constructor, $e); |
294 | - } finally { |
|
294 | + }finally{ |
|
295 | 295 | $this->tracer->pop(true); |
296 | 296 | $this->tracer->pop(false); |
297 | 297 | } |
298 | - } else { |
|
298 | + }else{ |
|
299 | 299 | // No constructor specified |
300 | 300 | $instance = $reflection->newInstance(); |
301 | 301 | } |
@@ -316,9 +316,9 @@ discard block |
||
316 | 316 | private function registerInstance(object $instance): object |
317 | 317 | { |
318 | 318 | //Declarative singletons |
319 | - if ($instance instanceof SingletonInterface) { |
|
319 | + if ($instance instanceof SingletonInterface){ |
|
320 | 320 | $alias = $instance::class; |
321 | - if (!isset($this->state->bindings[$alias])) { |
|
321 | + if (!isset($this->state->bindings[$alias])){ |
|
322 | 322 | $this->state->bindings[$alias] = $instance; |
323 | 323 | } |
324 | 324 | } |