@@ -13,7 +13,7 @@ |
||
13 | 13 | { |
14 | 14 | public function __construct( |
15 | 15 | private LoggerInterface $logger, |
16 | - ) { |
|
16 | + ){ |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | public function createInjection(\ReflectionClass $class, ?string $context = null): LoggerInterface |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | |
37 | 37 | public function testInvalidInjector(): void |
38 | 38 | { |
39 | - $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an " . |
|
39 | + $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an ". |
|
40 | 40 | "instance of InjectorInterface for 'Spiral\Tests\Core\Fixtures\TestConfig'"; |
41 | 41 | $this->expectException(InjectionException::class); |
42 | 42 | $this->expectExceptionMessage($excepted); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | public function testInvalidRuntimeInjector(): void |
64 | 64 | { |
65 | - $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an " . |
|
65 | + $excepted = "Class 'Spiral\Tests\Core\Fixtures\InvalidInjector' must be an ". |
|
66 | 66 | "instance of InjectorInterface for 'Spiral\Tests\Core\Fixtures\TestConfig'"; |
67 | 67 | $this->expectException(InjectionException::class); |
68 | 68 | $this->expectExceptionMessage($excepted); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $container->bind(ConfigsInterface::class, $configurator); |
100 | 100 | |
101 | 101 | $configurator->shouldReceive('createInjection') |
102 | - ->with(m::on(static function (ReflectionClass $r) { |
|
102 | + ->with(m::on(static function (ReflectionClass $r){ |
|
103 | 103 | return $r->getName() === TestConfig::class; |
104 | 104 | }), null) |
105 | 105 | ->andReturn($expected); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | $container->bind(ConfigsInterface::class, $configurator); |
117 | 117 | |
118 | 118 | $configurator->shouldReceive('createInjection') |
119 | - ->with(m::on(static function (ReflectionClass $r) { |
|
119 | + ->with(m::on(static function (ReflectionClass $r){ |
|
120 | 120 | return $r->getName() === TestConfig::class; |
121 | 121 | }), 'context') |
122 | 122 | ->andReturn($expected); |
@@ -99,7 +99,8 @@ discard block |
||
99 | 99 | $container->bind(ConfigsInterface::class, $configurator); |
100 | 100 | |
101 | 101 | $configurator->shouldReceive('createInjection') |
102 | - ->with(m::on(static function (ReflectionClass $r) { |
|
102 | + ->with(m::on(static function (ReflectionClass $r) |
|
103 | + { |
|
103 | 104 | return $r->getName() === TestConfig::class; |
104 | 105 | }), null) |
105 | 106 | ->andReturn($expected); |
@@ -116,7 +117,8 @@ discard block |
||
116 | 117 | $container->bind(ConfigsInterface::class, $configurator); |
117 | 118 | |
118 | 119 | $configurator->shouldReceive('createInjection') |
119 | - ->with(m::on(static function (ReflectionClass $r) { |
|
120 | + ->with(m::on(static function (ReflectionClass $r) |
|
121 | + { |
|
120 | 122 | return $r->getName() === TestConfig::class; |
121 | 123 | }), 'context') |
122 | 124 | ->andReturn($expected); |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | { |
136 | 136 | $container = new Container(); |
137 | 137 | |
138 | - try { |
|
138 | + try{ |
|
139 | 139 | $container->get('invalid'); |
140 | - } catch (ContainerException $e) { |
|
140 | + }catch (ContainerException $e){ |
|
141 | 141 | $this->assertSame( |
142 | 142 | <<<MARKDOWN |
143 | 143 | Can't resolve `invalid`: undefined class or binding `invalid`. |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | { |
170 | 170 | $this->expectException(ContainerException::class); |
171 | 171 | |
172 | - try { |
|
172 | + try{ |
|
173 | 173 | $container->get(ClassWithUndefinedDependency::class); |
174 | - } catch (ContainerException $e) { |
|
174 | + }catch (ContainerException $e){ |
|
175 | 175 | self::assertSame($message, $e->getMessage()); |
176 | 176 | |
177 | 177 | throw $e; |
@@ -135,9 +135,12 @@ discard block |
||
135 | 135 | { |
136 | 136 | $container = new Container(); |
137 | 137 | |
138 | - try { |
|
138 | + try |
|
139 | + { |
|
139 | 140 | $container->get('invalid'); |
140 | - } catch (ContainerException $e) { |
|
141 | + } |
|
142 | + catch (ContainerException $e) |
|
143 | + { |
|
141 | 144 | $this->assertSame( |
142 | 145 | <<<MARKDOWN |
143 | 146 | Can't resolve `invalid`: undefined class or binding `invalid`. |
@@ -169,9 +172,12 @@ discard block |
||
169 | 172 | { |
170 | 173 | $this->expectException(ContainerException::class); |
171 | 174 | |
172 | - try { |
|
175 | + try |
|
176 | + { |
|
173 | 177 | $container->get(ClassWithUndefinedDependency::class); |
174 | - } catch (ContainerException $e) { |
|
178 | + } |
|
179 | + catch (ContainerException $e) |
|
180 | + { |
|
175 | 181 | self::assertSame($message, $e->getMessage()); |
176 | 182 | |
177 | 183 | throw $e; |
@@ -28,7 +28,7 @@ |
||
28 | 28 | |
29 | 29 | public function hasInstance(string $alias): bool |
30 | 30 | { |
31 | - if (!$this->container->has($alias)) { |
|
31 | + if (!$this->container->has($alias)){ |
|
32 | 32 | return false; |
33 | 33 | } |
34 | 34 |
@@ -28,7 +28,8 @@ |
||
28 | 28 | |
29 | 29 | public function hasInstance(string $alias): bool |
30 | 30 | { |
31 | - if (!$this->container->has($alias)) { |
|
31 | + if (!$this->container->has($alias)) |
|
32 | + { |
|
32 | 33 | return false; |
33 | 34 | } |
34 | 35 |
@@ -19,14 +19,14 @@ discard block |
||
19 | 19 | |
20 | 20 | public function __construct( |
21 | 21 | public array $info = [], |
22 | - ) { |
|
22 | + ){ |
|
23 | 23 | $this->alias = $info['alias'] ?? null; |
24 | 24 | } |
25 | 25 | |
26 | 26 | public function __toString(): string |
27 | 27 | { |
28 | 28 | $info = []; |
29 | - foreach ($this->info as $key => $item) { |
|
29 | + foreach ($this->info as $key => $item){ |
|
30 | 30 | $info[] = "$key: {$this->stringifyValue($item)}"; |
31 | 31 | } |
32 | 32 | return \implode("\n", $info); |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | \is_scalar($item) => \var_export($item, true), |
40 | 40 | $item instanceof \Closure => $this->renderClosureSignature(new \ReflectionFunction($item)), |
41 | 41 | $item instanceof \ReflectionFunctionAbstract => $this->renderClosureSignature($item), |
42 | - $item instanceof \UnitEnum => $item::class . "::$item->name", |
|
43 | - \is_object($item) => $item instanceof \Stringable ? (string) $item : 'instance of ' . $item::class, |
|
42 | + $item instanceof \UnitEnum => $item::class."::$item->name", |
|
43 | + \is_object($item) => $item instanceof \Stringable ? (string)$item : 'instance of '.$item::class, |
|
44 | 44 | \is_array($item) => $this->renderArray($item), |
45 | 45 | default => \get_debug_type($item), |
46 | 46 | }; |
@@ -48,14 +48,14 @@ discard block |
||
48 | 48 | |
49 | 49 | private function renderArray(array $array, int $level = 0): string |
50 | 50 | { |
51 | - if ($array === []) { |
|
51 | + if ($array === []){ |
|
52 | 52 | return '[]'; |
53 | 53 | } |
54 | - if ($level >= self::ARRAY_MAX_LEVEL) { |
|
54 | + if ($level >= self::ARRAY_MAX_LEVEL){ |
|
55 | 55 | return 'array'; |
56 | 56 | } |
57 | 57 | $result = []; |
58 | - foreach ($array as $key => $value) { |
|
58 | + foreach ($array as $key => $value){ |
|
59 | 59 | $result[] = \sprintf( |
60 | 60 | '%s: %s', |
61 | 61 | $key, |
@@ -66,6 +66,6 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | $pad = \str_repeat(' ', $level); |
69 | - return "[\n $pad" . \implode(",\n $pad", $result) . "\n$pad]"; |
|
69 | + return "[\n $pad".\implode(",\n $pad", $result)."\n$pad]"; |
|
70 | 70 | } |
71 | 71 | } |
@@ -66,17 +66,20 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function make(string $alias, array $parameters = [], string $context = null): mixed |
68 | 68 | { |
69 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
69 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) |
|
70 | + { |
|
70 | 71 | return $this->state->singletons[$alias]; |
71 | 72 | } |
72 | 73 | |
73 | 74 | $binding = $this->state->bindings[$alias] ?? null; |
74 | 75 | |
75 | - if ($binding === null) { |
|
76 | + if ($binding === null) |
|
77 | + { |
|
76 | 78 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
77 | 79 | } |
78 | 80 | |
79 | - try { |
|
81 | + try |
|
82 | + { |
|
80 | 83 | $this->tracer->push( |
81 | 84 | false, |
82 | 85 | action: 'resolve from binding', |
@@ -100,7 +103,9 @@ discard block |
||
100 | 103 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
101 | 104 | default => $binding, |
102 | 105 | }; |
103 | - } finally { |
|
106 | + } |
|
107 | + finally |
|
108 | + { |
|
104 | 109 | $this->state->bindings[$alias] ??= $binding; |
105 | 110 | $this->tracer->pop(true); |
106 | 111 | $this->tracer->pop(false); |
@@ -116,23 +121,29 @@ discard block |
||
116 | 121 | $ctx = new Ctx(alias: $alias, class: $alias, parameter: $context); |
117 | 122 | |
118 | 123 | // We have to construct class using external injector when we know exact context |
119 | - if ($arguments !== []) { |
|
124 | + if ($arguments !== []) |
|
125 | + { |
|
120 | 126 | // todo factory? |
121 | 127 | } |
122 | 128 | |
123 | 129 | $class = $ctx->class; |
124 | - try { |
|
130 | + try |
|
131 | + { |
|
125 | 132 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
126 | - } catch (\ReflectionException $e) { |
|
133 | + } |
|
134 | + catch (\ReflectionException $e) |
|
135 | + { |
|
127 | 136 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
128 | 137 | } |
129 | 138 | |
130 | 139 | $injector = $binding->injector; |
131 | 140 | |
132 | - try { |
|
141 | + try |
|
142 | + { |
|
133 | 143 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
134 | 144 | |
135 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
145 | + if (!$injectorInstance instanceof InjectorInterface) |
|
146 | + { |
|
136 | 147 | throw new InjectionException( |
137 | 148 | \sprintf( |
138 | 149 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -147,7 +158,8 @@ discard block |
||
147 | 158 | * @psalm-suppress RedundantCondition |
148 | 159 | */ |
149 | 160 | $instance = $injectorInstance->createInjection($reflection, $ctx->parameter); |
150 | - if (!$reflection->isInstance($instance)) { |
|
161 | + if (!$reflection->isInstance($instance)) |
|
162 | + { |
|
151 | 163 | throw new InjectionException( |
152 | 164 | \sprintf( |
153 | 165 | "Invalid injection response for '%s'.", |
@@ -157,7 +169,9 @@ discard block |
||
157 | 169 | } |
158 | 170 | |
159 | 171 | return $instance; |
160 | - } finally { |
|
172 | + } |
|
173 | + finally |
|
174 | + { |
|
161 | 175 | $this->state->bindings[$reflection->getName()] ??= $binding; //new Injector($injector); |
162 | 176 | } |
163 | 177 | } |
@@ -176,7 +190,8 @@ discard block |
||
176 | 190 | //Binding is pointing to something else |
177 | 191 | : $this->make($binding->alias, $arguments, $context); |
178 | 192 | |
179 | - if ($binding->singleton && $arguments === []) { |
|
193 | + if ($binding->singleton && $arguments === []) |
|
194 | + { |
|
180 | 195 | $this->state->singletons[$alias] = $result; |
181 | 196 | } |
182 | 197 | |
@@ -217,11 +232,14 @@ discard block |
||
217 | 232 | array $arguments, |
218 | 233 | ): mixed { |
219 | 234 | $ctx = new Ctx(alias: $alias, class: $alias, parameter: $context, singleton: $binding->singleton); |
220 | - try { |
|
235 | + try |
|
236 | + { |
|
221 | 237 | $instance = $binding::class === \Spiral\Core\Config\Factory::class && $binding->getParametersCount() === 0 |
222 | 238 | ? ($binding->factory)() |
223 | 239 | : $this->invoker->invoke($binding->factory, $arguments); |
224 | - } catch (NotCallableException $e) { |
|
240 | + } |
|
241 | + catch (NotCallableException $e) |
|
242 | + { |
|
225 | 243 | throw new ContainerException( |
226 | 244 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
227 | 245 | $e->getCode(), |
@@ -240,19 +258,24 @@ discard block |
||
240 | 258 | ): ?object { |
241 | 259 | $avoidCache = $arguments !== []; |
242 | 260 | |
243 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
244 | - try { |
|
261 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) |
|
262 | + { |
|
263 | + try |
|
264 | + { |
|
245 | 265 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
246 | 266 | |
247 | 267 | $object = $this->createInstance( |
248 | 268 | new Ctx(alias: $alias, class: $alias, parameter: $context), |
249 | 269 | $arguments, |
250 | 270 | ); |
251 | - if ($avoidCache) { |
|
271 | + if ($avoidCache) |
|
272 | + { |
|
252 | 273 | return $object; |
253 | 274 | } |
254 | 275 | $binding->reference = WeakReference::create($object); |
255 | - } catch (\Throwable) { |
|
276 | + } |
|
277 | + catch (\Throwable) |
|
278 | + { |
|
256 | 279 | throw new ContainerException( |
257 | 280 | $this->tracer->combineTraceMessage( |
258 | 281 | \sprintf( |
@@ -262,7 +285,9 @@ discard block |
||
262 | 285 | ) |
263 | 286 | ) |
264 | 287 | ); |
265 | - } finally { |
|
288 | + } |
|
289 | + finally |
|
290 | + { |
|
266 | 291 | $this->tracer->pop(); |
267 | 292 | } |
268 | 293 | } |
@@ -274,18 +299,25 @@ discard block |
||
274 | 299 | { |
275 | 300 | $parent = $this->scope->getParent(); |
276 | 301 | |
277 | - if ($parent !== null) { |
|
278 | - try { |
|
302 | + if ($parent !== null) |
|
303 | + { |
|
304 | + try |
|
305 | + { |
|
279 | 306 | $this->tracer->push(false, ...[ |
280 | 307 | 'current scope' => $this->scope->getScopeName(), |
281 | 308 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
282 | 309 | ]); |
283 | 310 | return $parent->make($alias, $parameters, $context); |
284 | - } catch (BadScopeException $e) { |
|
285 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
311 | + } |
|
312 | + catch (BadScopeException $e) |
|
313 | + { |
|
314 | + if ($this->scope->getScopeName() !== $e->getScope()) |
|
315 | + { |
|
286 | 316 | throw $e; |
287 | 317 | } |
288 | - } catch (ContainerExceptionInterface $e) { |
|
318 | + } |
|
319 | + catch (ContainerExceptionInterface $e) |
|
320 | + { |
|
289 | 321 | $className = match (true) { |
290 | 322 | $e instanceof NotFoundException => NotFoundException::class, |
291 | 323 | default => ContainerException::class, |
@@ -294,19 +326,24 @@ discard block |
||
294 | 326 | 'Can\'t resolve `%s`.', |
295 | 327 | $alias, |
296 | 328 | )), previous: $e); |
297 | - } finally { |
|
329 | + } |
|
330 | + finally |
|
331 | + { |
|
298 | 332 | $this->tracer->pop(false); |
299 | 333 | } |
300 | 334 | } |
301 | 335 | |
302 | 336 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
303 | - try { |
|
337 | + try |
|
338 | + { |
|
304 | 339 | //No direct instructions how to construct class, make is automatically |
305 | 340 | return $this->autowire( |
306 | 341 | new Ctx(alias: $alias, class: $alias, parameter: $context), |
307 | 342 | $parameters, |
308 | 343 | ); |
309 | - } finally { |
|
344 | + } |
|
345 | + finally |
|
346 | + { |
|
310 | 347 | $this->tracer->pop(false); |
311 | 348 | } |
312 | 349 | } |
@@ -357,7 +394,8 @@ discard block |
||
357 | 394 | // Check scope name |
358 | 395 | $ctx->reflection = new \ReflectionClass($instance); |
359 | 396 | $scopeName = ($ctx->reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
360 | - if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) { |
|
397 | + if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) |
|
398 | + { |
|
361 | 399 | throw new BadScopeException($scopeName, $instance::class); |
362 | 400 | } |
363 | 401 | |
@@ -384,24 +422,30 @@ discard block |
||
384 | 422 | array $parameters, |
385 | 423 | ): object { |
386 | 424 | $class = $ctx->class; |
387 | - try { |
|
425 | + try |
|
426 | + { |
|
388 | 427 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
389 | - } catch (\ReflectionException $e) { |
|
428 | + } |
|
429 | + catch (\ReflectionException $e) |
|
430 | + { |
|
390 | 431 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
391 | 432 | } |
392 | 433 | |
393 | 434 | // Check scope name |
394 | 435 | $scope = ($reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
395 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
436 | + if ($scope !== null && $scope !== $this->scope->getScopeName()) |
|
437 | + { |
|
396 | 438 | throw new BadScopeException($scope, $class); |
397 | 439 | } |
398 | 440 | |
399 | 441 | //We have to construct class using external injector when we know exact context |
400 | - if ($parameters === [] && $this->binder->hasInjector($class)) { |
|
442 | + if ($parameters === [] && $this->binder->hasInjector($class)) |
|
443 | + { |
|
401 | 444 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx->class, $ctx->parameter, $parameters); |
402 | 445 | } |
403 | 446 | |
404 | - if (!$reflection->isInstantiable()) { |
|
447 | + if (!$reflection->isInstantiable()) |
|
448 | + { |
|
405 | 449 | $itIs = match (true) { |
406 | 450 | $reflection->isEnum() => 'Enum', |
407 | 451 | $reflection->isAbstract() => 'Abstract class', |
@@ -414,12 +458,16 @@ discard block |
||
414 | 458 | |
415 | 459 | $constructor = $reflection->getConstructor(); |
416 | 460 | |
417 | - if ($constructor !== null) { |
|
418 | - try { |
|
461 | + if ($constructor !== null) |
|
462 | + { |
|
463 | + try |
|
464 | + { |
|
419 | 465 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
420 | 466 | $this->tracer->push(true); |
421 | 467 | $arguments = $this->resolver->resolveArguments($constructor, $parameters); |
422 | - } catch (ValidationException $e) { |
|
468 | + } |
|
469 | + catch (ValidationException $e) |
|
470 | + { |
|
423 | 471 | throw new ContainerException( |
424 | 472 | $this->tracer->combineTraceMessage( |
425 | 473 | \sprintf( |
@@ -429,22 +477,31 @@ discard block |
||
429 | 477 | ) |
430 | 478 | ), |
431 | 479 | ); |
432 | - } finally { |
|
480 | + } |
|
481 | + finally |
|
482 | + { |
|
433 | 483 | $this->tracer->pop(true); |
434 | 484 | $this->tracer->pop(false); |
435 | 485 | } |
436 | - try { |
|
486 | + try |
|
487 | + { |
|
437 | 488 | // Using constructor with resolved arguments |
438 | 489 | $this->tracer->push(false, call: "$class::__construct", arguments: $arguments); |
439 | 490 | $this->tracer->push(true); |
440 | 491 | $instance = new $class(...$arguments); |
441 | - } catch (\TypeError $e) { |
|
492 | + } |
|
493 | + catch (\TypeError $e) |
|
494 | + { |
|
442 | 495 | throw new WrongTypeException($constructor, $e); |
443 | - } finally { |
|
496 | + } |
|
497 | + finally |
|
498 | + { |
|
444 | 499 | $this->tracer->pop(true); |
445 | 500 | $this->tracer->pop(false); |
446 | 501 | } |
447 | - } else { |
|
502 | + } |
|
503 | + else |
|
504 | + { |
|
448 | 505 | // No constructor specified |
449 | 506 | $instance = $reflection->newInstance(); |
450 | 507 | } |
@@ -470,13 +527,15 @@ discard block |
||
470 | 527 | $instance = $this->runInflector($instance); |
471 | 528 | |
472 | 529 | //Declarative singletons |
473 | - if ($this->isSingleton($ctx)) { |
|
530 | + if ($this->isSingleton($ctx)) |
|
531 | + { |
|
474 | 532 | $this->state->singletons[$ctx->alias] = $instance; |
475 | 533 | } |
476 | 534 | |
477 | 535 | // Register finalizer |
478 | 536 | $finalizer = $this->getFinalizer($ctx, $instance); |
479 | - if ($finalizer !== null) { |
|
537 | + if ($finalizer !== null) |
|
538 | + { |
|
480 | 539 | $this->state->finalizers[] = $finalizer; |
481 | 540 | } |
482 | 541 | |
@@ -488,12 +547,14 @@ discard block |
||
488 | 547 | */ |
489 | 548 | private function isSingleton(Ctx $ctx): bool |
490 | 549 | { |
491 | - if ($ctx->singleton === true) { |
|
550 | + if ($ctx->singleton === true) |
|
551 | + { |
|
492 | 552 | return true; |
493 | 553 | } |
494 | 554 | |
495 | 555 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
496 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
556 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)) |
|
557 | + { |
|
497 | 558 | return true; |
498 | 559 | } |
499 | 560 | |
@@ -507,7 +568,8 @@ discard block |
||
507 | 568 | * @var Finalize|null $attribute |
508 | 569 | */ |
509 | 570 | $attribute = ($ctx->reflection->getAttributes(Finalize::class)[0] ?? null)?->newInstance(); |
510 | - if ($attribute === null) { |
|
571 | + if ($attribute === null) |
|
572 | + { |
|
511 | 573 | return null; |
512 | 574 | } |
513 | 575 | |
@@ -521,10 +583,14 @@ discard block |
||
521 | 583 | { |
522 | 584 | $scope = $this->scope; |
523 | 585 | |
524 | - while ($scope !== null) { |
|
525 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
526 | - if ($instance instanceof $class) { |
|
527 | - foreach ($inflectors as $inflector) { |
|
586 | + while ($scope !== null) |
|
587 | + { |
|
588 | + foreach ($this->state->inflectors as $class => $inflectors) |
|
589 | + { |
|
590 | + if ($instance instanceof $class) |
|
591 | + { |
|
592 | + foreach ($inflectors as $inflector) |
|
593 | + { |
|
528 | 594 | $instance = $inflector->getParametersCount() > 1 |
529 | 595 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
530 | 596 | : ($inflector->inflector)($instance); |
@@ -66,17 +66,17 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function make(string $alias, array $parameters = [], string $context = null): mixed |
68 | 68 | { |
69 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
69 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)){ |
|
70 | 70 | return $this->state->singletons[$alias]; |
71 | 71 | } |
72 | 72 | |
73 | 73 | $binding = $this->state->bindings[$alias] ?? null; |
74 | 74 | |
75 | - if ($binding === null) { |
|
75 | + if ($binding === null){ |
|
76 | 76 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
77 | 77 | } |
78 | 78 | |
79 | - try { |
|
79 | + try{ |
|
80 | 80 | $this->tracer->push( |
81 | 81 | false, |
82 | 82 | action: 'resolve from binding', |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
101 | 101 | default => $binding, |
102 | 102 | }; |
103 | - } finally { |
|
103 | + }finally{ |
|
104 | 104 | $this->state->bindings[$alias] ??= $binding; |
105 | 105 | $this->tracer->pop(true); |
106 | 106 | $this->tracer->pop(false); |
@@ -112,27 +112,27 @@ discard block |
||
112 | 112 | string $alias, |
113 | 113 | ?string $context, |
114 | 114 | array $arguments, |
115 | - ) { |
|
116 | - $ctx = new Ctx(alias: $alias, class: $alias, parameter: $context); |
|
115 | + ){ |
|
116 | + $ctx = new Ctx(alias : $alias, class : $alias, parameter : $context); |
|
117 | 117 | |
118 | 118 | // We have to construct class using external injector when we know exact context |
119 | - if ($arguments !== []) { |
|
119 | + if ($arguments !== []){ |
|
120 | 120 | // todo factory? |
121 | 121 | } |
122 | 122 | |
123 | 123 | $class = $ctx->class; |
124 | - try { |
|
124 | + try{ |
|
125 | 125 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
126 | - } catch (\ReflectionException $e) { |
|
126 | + }catch (\ReflectionException $e){ |
|
127 | 127 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
128 | 128 | } |
129 | 129 | |
130 | 130 | $injector = $binding->injector; |
131 | 131 | |
132 | - try { |
|
132 | + try{ |
|
133 | 133 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
134 | 134 | |
135 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
135 | + if (!$injectorInstance instanceof InjectorInterface){ |
|
136 | 136 | throw new InjectionException( |
137 | 137 | \sprintf( |
138 | 138 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * @psalm-suppress RedundantCondition |
147 | 147 | */ |
148 | 148 | $instance = $injectorInstance->createInjection($reflection, $ctx->parameter); |
149 | - if (!$reflection->isInstance($instance)) { |
|
149 | + if (!$reflection->isInstance($instance)){ |
|
150 | 150 | throw new InjectionException( |
151 | 151 | \sprintf( |
152 | 152 | "Invalid injection response for '%s'.", |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | } |
157 | 157 | |
158 | 158 | return $instance; |
159 | - } finally { |
|
159 | + }finally{ |
|
160 | 160 | $this->state->bindings[$reflection->getName()] ??= $binding; //new Injector($injector); |
161 | 161 | } |
162 | 162 | } |
@@ -169,13 +169,13 @@ discard block |
||
169 | 169 | ): mixed { |
170 | 170 | $result = $binding->alias === $alias |
171 | 171 | ? $this->autowire( |
172 | - new Ctx(alias: $alias, class: $binding->alias, parameter: $context, singleton: $binding->singleton), |
|
172 | + new Ctx(alias : $alias, class : $binding->alias, parameter : $context, singleton : $binding->singleton), |
|
173 | 173 | $arguments, |
174 | 174 | ) |
175 | 175 | //Binding is pointing to something else |
176 | 176 | : $this->make($binding->alias, $arguments, $context); |
177 | 177 | |
178 | - if ($binding->singleton && $arguments === []) { |
|
178 | + if ($binding->singleton && $arguments === []){ |
|
179 | 179 | $this->state->singletons[$alias] = $result; |
180 | 180 | } |
181 | 181 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | $avoidCache = $arguments !== []; |
192 | 192 | return $avoidCache |
193 | 193 | ? $this->createInstance( |
194 | - new Ctx(alias: $alias, class: $binding->value::class, parameter: $context), |
|
194 | + new Ctx(alias : $alias, class : $binding->value::class, parameter : $context), |
|
195 | 195 | $arguments, |
196 | 196 | ) |
197 | 197 | : $binding->value; |
@@ -210,17 +210,17 @@ discard block |
||
210 | 210 | } |
211 | 211 | |
212 | 212 | private function resolveFactory( |
213 | - \Spiral\Core\Config\Factory|DeferredFactory $binding, |
|
213 | + \Spiral\Core\Config\Factory | DeferredFactory $binding, |
|
214 | 214 | string $alias, |
215 | 215 | ?string $context, |
216 | 216 | array $arguments, |
217 | 217 | ): mixed { |
218 | - $ctx = new Ctx(alias: $alias, class: $alias, parameter: $context, singleton: $binding->singleton); |
|
219 | - try { |
|
218 | + $ctx = new Ctx(alias : $alias, class : $alias, parameter : $context, singleton : $binding->singleton); |
|
219 | + try{ |
|
220 | 220 | $instance = $binding::class === \Spiral\Core\Config\Factory::class && $binding->getParametersCount() === 0 |
221 | 221 | ? ($binding->factory)() |
222 | 222 | : $this->invoker->invoke($binding->factory, $arguments); |
223 | - } catch (NotCallableException $e) { |
|
223 | + }catch (NotCallableException $e){ |
|
224 | 224 | throw new ContainerException( |
225 | 225 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
226 | 226 | $e->getCode(), |
@@ -239,19 +239,19 @@ discard block |
||
239 | 239 | ): ?object { |
240 | 240 | $avoidCache = $arguments !== []; |
241 | 241 | |
242 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
243 | - try { |
|
242 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)){ |
|
243 | + try{ |
|
244 | 244 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
245 | 245 | |
246 | 246 | $object = $this->createInstance( |
247 | 247 | new Ctx(alias: $alias, class: $alias, parameter: $context), |
248 | 248 | $arguments, |
249 | 249 | ); |
250 | - if ($avoidCache) { |
|
250 | + if ($avoidCache){ |
|
251 | 251 | return $object; |
252 | 252 | } |
253 | 253 | $binding->reference = WeakReference::create($object); |
254 | - } catch (\Throwable) { |
|
254 | + }catch (\Throwable){ |
|
255 | 255 | throw new ContainerException( |
256 | 256 | $this->tracer->combineTraceMessage( |
257 | 257 | \sprintf( |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | ) |
262 | 262 | ) |
263 | 263 | ); |
264 | - } finally { |
|
264 | + }finally{ |
|
265 | 265 | $this->tracer->pop(); |
266 | 266 | } |
267 | 267 | } |
@@ -273,18 +273,18 @@ discard block |
||
273 | 273 | { |
274 | 274 | $parent = $this->scope->getParent(); |
275 | 275 | |
276 | - if ($parent !== null) { |
|
277 | - try { |
|
276 | + if ($parent !== null){ |
|
277 | + try{ |
|
278 | 278 | $this->tracer->push(false, ...[ |
279 | 279 | 'current scope' => $this->scope->getScopeName(), |
280 | 280 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
281 | 281 | ]); |
282 | 282 | return $parent->make($alias, $parameters, $context); |
283 | - } catch (BadScopeException $e) { |
|
284 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
283 | + }catch (BadScopeException $e){ |
|
284 | + if ($this->scope->getScopeName() !== $e->getScope()){ |
|
285 | 285 | throw $e; |
286 | 286 | } |
287 | - } catch (ContainerExceptionInterface $e) { |
|
287 | + }catch (ContainerExceptionInterface $e){ |
|
288 | 288 | $className = match (true) { |
289 | 289 | $e instanceof NotFoundException => NotFoundException::class, |
290 | 290 | default => ContainerException::class, |
@@ -293,19 +293,19 @@ discard block |
||
293 | 293 | 'Can\'t resolve `%s`.', |
294 | 294 | $alias, |
295 | 295 | )), previous: $e); |
296 | - } finally { |
|
296 | + }finally{ |
|
297 | 297 | $this->tracer->pop(false); |
298 | 298 | } |
299 | 299 | } |
300 | 300 | |
301 | 301 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
302 | - try { |
|
302 | + try{ |
|
303 | 303 | //No direct instructions how to construct class, make is automatically |
304 | 304 | return $this->autowire( |
305 | 305 | new Ctx(alias: $alias, class: $alias, parameter: $context), |
306 | 306 | $parameters, |
307 | 307 | ); |
308 | - } finally { |
|
308 | + }finally{ |
|
309 | 309 | $this->tracer->pop(false); |
310 | 310 | } |
311 | 311 | } |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | && |
328 | 328 | (isset($this->state->injectors[$ctx->class]) || $this->binder->hasInjector($ctx->class)) |
329 | 329 | )) |
330 | - ) { |
|
330 | + ){ |
|
331 | 331 | throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf( |
332 | 332 | 'Can\'t resolve `%s`: undefined class or binding `%s`.', |
333 | 333 | $this->tracer->getRootAlias(), |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | // Check scope name |
357 | 357 | $ctx->reflection = new \ReflectionClass($instance); |
358 | 358 | $scopeName = ($ctx->reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
359 | - if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) { |
|
359 | + if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()){ |
|
360 | 360 | throw new BadScopeException($scopeName, $instance::class); |
361 | 361 | } |
362 | 362 | |
@@ -383,24 +383,24 @@ discard block |
||
383 | 383 | array $parameters, |
384 | 384 | ): object { |
385 | 385 | $class = $ctx->class; |
386 | - try { |
|
386 | + try{ |
|
387 | 387 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
388 | - } catch (\ReflectionException $e) { |
|
388 | + }catch (\ReflectionException $e){ |
|
389 | 389 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
390 | 390 | } |
391 | 391 | |
392 | 392 | // Check scope name |
393 | 393 | $scope = ($reflection->getAttributes(ScopeAttribute::class)[0] ?? null)?->newInstance()->name; |
394 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
394 | + if ($scope !== null && $scope !== $this->scope->getScopeName()){ |
|
395 | 395 | throw new BadScopeException($scope, $class); |
396 | 396 | } |
397 | 397 | |
398 | 398 | //We have to construct class using external injector when we know exact context |
399 | - if ($parameters === [] && $this->binder->hasInjector($class)) { |
|
399 | + if ($parameters === [] && $this->binder->hasInjector($class)){ |
|
400 | 400 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx->class, $ctx->parameter, $parameters); |
401 | 401 | } |
402 | 402 | |
403 | - if (!$reflection->isInstantiable()) { |
|
403 | + if (!$reflection->isInstantiable()){ |
|
404 | 404 | $itIs = match (true) { |
405 | 405 | $reflection->isEnum() => 'Enum', |
406 | 406 | $reflection->isAbstract() => 'Abstract class', |
@@ -413,12 +413,12 @@ discard block |
||
413 | 413 | |
414 | 414 | $constructor = $reflection->getConstructor(); |
415 | 415 | |
416 | - if ($constructor !== null) { |
|
417 | - try { |
|
416 | + if ($constructor !== null){ |
|
417 | + try{ |
|
418 | 418 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
419 | 419 | $this->tracer->push(true); |
420 | 420 | $arguments = $this->resolver->resolveArguments($constructor, $parameters); |
421 | - } catch (ValidationException $e) { |
|
421 | + }catch (ValidationException $e){ |
|
422 | 422 | throw new ContainerException( |
423 | 423 | $this->tracer->combineTraceMessage( |
424 | 424 | \sprintf( |
@@ -428,22 +428,22 @@ discard block |
||
428 | 428 | ) |
429 | 429 | ), |
430 | 430 | ); |
431 | - } finally { |
|
431 | + }finally{ |
|
432 | 432 | $this->tracer->pop(true); |
433 | 433 | $this->tracer->pop(false); |
434 | 434 | } |
435 | - try { |
|
435 | + try{ |
|
436 | 436 | // Using constructor with resolved arguments |
437 | 437 | $this->tracer->push(false, call: "$class::__construct", arguments: $arguments); |
438 | 438 | $this->tracer->push(true); |
439 | 439 | $instance = new $class(...$arguments); |
440 | - } catch (\TypeError $e) { |
|
440 | + }catch (\TypeError $e){ |
|
441 | 441 | throw new WrongTypeException($constructor, $e); |
442 | - } finally { |
|
442 | + }finally{ |
|
443 | 443 | $this->tracer->pop(true); |
444 | 444 | $this->tracer->pop(false); |
445 | 445 | } |
446 | - } else { |
|
446 | + }else{ |
|
447 | 447 | // No constructor specified |
448 | 448 | $instance = $reflection->newInstance(); |
449 | 449 | } |
@@ -461,13 +461,13 @@ discard block |
||
461 | 461 | $instance = $this->runInflector($instance); |
462 | 462 | |
463 | 463 | //Declarative singletons |
464 | - if ($this->isSingleton($ctx)) { |
|
464 | + if ($this->isSingleton($ctx)){ |
|
465 | 465 | $this->state->singletons[$ctx->alias] = $instance; |
466 | 466 | } |
467 | 467 | |
468 | 468 | // Register finalizer |
469 | 469 | $finalizer = $this->getFinalizer($ctx, $instance); |
470 | - if ($finalizer !== null) { |
|
470 | + if ($finalizer !== null){ |
|
471 | 471 | $this->state->finalizers[] = $finalizer; |
472 | 472 | } |
473 | 473 | |
@@ -479,12 +479,12 @@ discard block |
||
479 | 479 | */ |
480 | 480 | private function isSingleton(Ctx $ctx): bool |
481 | 481 | { |
482 | - if ($ctx->singleton === true) { |
|
482 | + if ($ctx->singleton === true){ |
|
483 | 483 | return true; |
484 | 484 | } |
485 | 485 | |
486 | 486 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
487 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
487 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)){ |
|
488 | 488 | return true; |
489 | 489 | } |
490 | 490 | |
@@ -498,7 +498,7 @@ discard block |
||
498 | 498 | * @var Finalize|null $attribute |
499 | 499 | */ |
500 | 500 | $attribute = ($ctx->reflection->getAttributes(Finalize::class)[0] ?? null)?->newInstance(); |
501 | - if ($attribute === null) { |
|
501 | + if ($attribute === null){ |
|
502 | 502 | return null; |
503 | 503 | } |
504 | 504 | |
@@ -512,10 +512,10 @@ discard block |
||
512 | 512 | { |
513 | 513 | $scope = $this->scope; |
514 | 514 | |
515 | - while ($scope !== null) { |
|
516 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
517 | - if ($instance instanceof $class) { |
|
518 | - foreach ($inflectors as $inflector) { |
|
515 | + while ($scope !== null){ |
|
516 | + foreach ($this->state->inflectors as $class => $inflectors){ |
|
517 | + if ($instance instanceof $class){ |
|
518 | + foreach ($inflectors as $inflector){ |
|
519 | 519 | $instance = $inflector->getParametersCount() > 1 |
520 | 520 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
521 | 521 | : ($inflector->inflector)($instance); |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | ): array { |
53 | 53 | $state = new ResolvingState($reflection, $parameters); |
54 | 54 | |
55 | - foreach ($reflection->getParameters() as $parameter) { |
|
55 | + foreach ($reflection->getParameters() as $parameter){ |
|
56 | 56 | $this->resolveParameter($parameter, $state, $validate) |
57 | 57 | or |
58 | 58 | throw new ArgumentResolvingException($reflection, $parameter->getName()); |
@@ -66,47 +66,47 @@ discard block |
||
66 | 66 | $positional = true; |
67 | 67 | $variadic = false; |
68 | 68 | $parameters = $reflection->getParameters(); |
69 | - if (\count($parameters) === 0) { |
|
69 | + if (\count($parameters) === 0){ |
|
70 | 70 | return; |
71 | 71 | } |
72 | 72 | |
73 | 73 | $parameter = null; |
74 | - while (\count($parameters) > 0 || \count($arguments) > 0) { |
|
74 | + while (\count($parameters) > 0 || \count($arguments) > 0){ |
|
75 | 75 | // get related argument value |
76 | 76 | $key = \key($arguments); |
77 | 77 | |
78 | 78 | // For a variadic parameter it's no sense - named or positional argument will be sent |
79 | 79 | // But you can't send positional argument after named in any case |
80 | - if (\is_int($key) && !$positional) { |
|
80 | + if (\is_int($key) && !$positional){ |
|
81 | 81 | throw new PositionalArgumentException($reflection, $key); |
82 | 82 | } |
83 | 83 | |
84 | 84 | $positional = $positional && \is_int($key); |
85 | 85 | |
86 | - if (!$variadic) { |
|
86 | + if (!$variadic){ |
|
87 | 87 | $parameter = \array_shift($parameters); |
88 | 88 | $variadic = $parameter?->isVariadic() ?? false; |
89 | 89 | } |
90 | 90 | |
91 | - if ($parameter === null) { |
|
91 | + if ($parameter === null){ |
|
92 | 92 | throw new UnknownParameterException($reflection, $key); |
93 | 93 | } |
94 | 94 | $name = $parameter->getName(); |
95 | 95 | |
96 | - if (($positional || $variadic) && $key !== null) { |
|
96 | + if (($positional || $variadic) && $key !== null){ |
|
97 | 97 | /** @psalm-suppress ReferenceReusedFromConfusingScope */ |
98 | 98 | $value = \array_shift($arguments); |
99 | - } elseif ($key === null || !\array_key_exists($name, $arguments)) { |
|
100 | - if ($parameter->isOptional()) { |
|
99 | + } elseif ($key === null || !\array_key_exists($name, $arguments)){ |
|
100 | + if ($parameter->isOptional()){ |
|
101 | 101 | continue; |
102 | 102 | } |
103 | 103 | throw new MissingRequiredArgumentException($reflection, $name); |
104 | - } else { |
|
104 | + }else{ |
|
105 | 105 | $value = &$arguments[$name]; |
106 | 106 | unset($arguments[$name]); |
107 | 107 | } |
108 | 108 | |
109 | - if (!$this->validateValueToParameter($parameter, $value)) { |
|
109 | + if (!$this->validateValueToParameter($parameter, $value)){ |
|
110 | 110 | throw new InvalidArgumentException($reflection, $name); |
111 | 111 | } |
112 | 112 | } |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | |
115 | 115 | private function validateValueToParameter(ReflectionParameter $parameter, mixed $value): bool |
116 | 116 | { |
117 | - if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)) { |
|
117 | + if (!$parameter->hasType() || ($parameter->allowsNull() && $value === null)){ |
|
118 | 118 | return true; |
119 | 119 | } |
120 | 120 | $type = $parameter->getType(); |
@@ -125,17 +125,17 @@ discard block |
||
125 | 125 | $type instanceof ReflectionIntersectionType => [false, $type->getTypes()], |
126 | 126 | }; |
127 | 127 | |
128 | - foreach ($types as $t) { |
|
128 | + foreach ($types as $t){ |
|
129 | 129 | \assert($t instanceof ReflectionNamedType); |
130 | - if (!$this->validateValueNamedType($t, $value)) { |
|
130 | + if (!$this->validateValueNamedType($t, $value)){ |
|
131 | 131 | // If it is TypeIntersection |
132 | - if ($or) { |
|
132 | + if ($or){ |
|
133 | 133 | continue; |
134 | 134 | } |
135 | 135 | return false; |
136 | 136 | } |
137 | 137 | // If it is not type intersection then we can skip that value after first successful check |
138 | - if ($or) { |
|
138 | + if ($or){ |
|
139 | 139 | return true; |
140 | 140 | } |
141 | 141 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | { |
151 | 151 | $name = $type->getName(); |
152 | 152 | |
153 | - if ($type->isBuiltin()) { |
|
153 | + if ($type->isBuiltin()){ |
|
154 | 154 | return match ($name) { |
155 | 155 | 'mixed' => true, |
156 | 156 | 'string' => \is_string($value), |
@@ -183,13 +183,13 @@ discard block |
||
183 | 183 | |
184 | 184 | // Try to resolve parameter by name |
185 | 185 | $res = $state->resolveParameterByNameOrPosition($parameter, $isVariadic); |
186 | - if ($res !== [] || $isVariadic) { |
|
186 | + if ($res !== [] || $isVariadic){ |
|
187 | 187 | // validate |
188 | - if ($isVariadic) { |
|
189 | - foreach ($res as $k => &$v) { |
|
190 | - $this->processArgument($state, $v, validateWith: $validate ? $parameter : null, key: $k); |
|
188 | + if ($isVariadic){ |
|
189 | + foreach ($res as $k => &$v){ |
|
190 | + $this->processArgument($state, $v, validateWith: $validate ? $parameter : null, key : $k); |
|
191 | 191 | } |
192 | - } else { |
|
192 | + }else{ |
|
193 | 193 | $this->processArgument($state, $res[0], validateWith: $validate ? $parameter : null); |
194 | 194 | } |
195 | 195 | |
@@ -197,39 +197,39 @@ discard block |
||
197 | 197 | } |
198 | 198 | |
199 | 199 | $error = null; |
200 | - if ($hasType) { |
|
200 | + if ($hasType){ |
|
201 | 201 | /** @var ReflectionIntersectionType|ReflectionUnionType|ReflectionNamedType $reflectionType */ |
202 | 202 | $reflectionType = $parameter->getType(); |
203 | 203 | |
204 | - if ($reflectionType instanceof ReflectionIntersectionType) { |
|
204 | + if ($reflectionType instanceof ReflectionIntersectionType){ |
|
205 | 205 | throw new UnsupportedTypeException($parameter->getDeclaringFunction(), $parameter->getName()); |
206 | 206 | } |
207 | 207 | |
208 | 208 | $types = $reflectionType instanceof ReflectionNamedType ? [$reflectionType] : $reflectionType->getTypes(); |
209 | - foreach ($types as $namedType) { |
|
210 | - try { |
|
211 | - if ($this->resolveNamedType($state, $parameter, $namedType, $validate)) { |
|
209 | + foreach ($types as $namedType){ |
|
210 | + try{ |
|
211 | + if ($this->resolveNamedType($state, $parameter, $namedType, $validate)){ |
|
212 | 212 | return true; |
213 | 213 | } |
214 | - } catch (Throwable $e) { |
|
214 | + }catch (Throwable $e){ |
|
215 | 215 | $error = $e; |
216 | 216 | } |
217 | 217 | } |
218 | 218 | } |
219 | 219 | |
220 | - if ($parameter->isDefaultValueAvailable()) { |
|
220 | + if ($parameter->isDefaultValueAvailable()){ |
|
221 | 221 | $argument = $parameter->getDefaultValue(); |
222 | 222 | $this->processArgument($state, $argument); |
223 | 223 | return true; |
224 | 224 | } |
225 | 225 | |
226 | - if ($hasType && $parameter->allowsNull()) { |
|
226 | + if ($hasType && $parameter->allowsNull()){ |
|
227 | 227 | $argument = null; |
228 | 228 | $this->processArgument($state, $argument); |
229 | 229 | return true; |
230 | 230 | } |
231 | 231 | |
232 | - if ($error === null) { |
|
232 | + if ($error === null){ |
|
233 | 233 | return false; |
234 | 234 | } |
235 | 235 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | ReflectionParameter $parameter, |
251 | 251 | ReflectionNamedType $typeRef, |
252 | 252 | bool $validate, |
253 | - ) { |
|
253 | + ){ |
|
254 | 254 | return !$typeRef->isBuiltin() && $this->resolveObjectParameter( |
255 | 255 | $state, |
256 | 256 | $typeRef->getName(), |
@@ -293,15 +293,15 @@ discard block |
||
293 | 293 | ResolvingState $state, |
294 | 294 | mixed &$value, |
295 | 295 | ReflectionParameter $validateWith = null, |
296 | - int|string $key = null |
|
296 | + int | string $key = null |
|
297 | 297 | ): void { |
298 | 298 | // Resolve Autowire objects |
299 | - if ($value instanceof Autowire) { |
|
299 | + if ($value instanceof Autowire){ |
|
300 | 300 | $value = $value->resolve($this->factory); |
301 | 301 | } |
302 | 302 | |
303 | 303 | // Validation |
304 | - if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)) { |
|
304 | + if ($validateWith !== null && !$this->validateValueToParameter($validateWith, $value)){ |
|
305 | 305 | throw new InvalidArgumentException( |
306 | 306 | $validateWith->getDeclaringFunction(), |
307 | 307 | $validateWith->getName() |
@@ -7,8 +7,8 @@ |
||
7 | 7 | final class Scalar extends Binding |
8 | 8 | { |
9 | 9 | public function __construct( |
10 | - public readonly bool|int|string|float $value, |
|
11 | - ) { |
|
10 | + public readonly bool | int | string | float $value, |
|
11 | + ){ |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | public function __toString(): string |
@@ -17,8 +17,8 @@ |
||
17 | 17 | * @param string|InjectorInterface $injector Injector object or binding alias. |
18 | 18 | */ |
19 | 19 | public function __construct( |
20 | - public readonly string|InjectorInterface $injector, |
|
21 | - ) { |
|
20 | + public readonly string | InjectorInterface $injector, |
|
21 | + ){ |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function __toString(): string |