@@ -13,20 +13,20 @@ |
||
13 | 13 | { |
14 | 14 | public function __construct( |
15 | 15 | private readonly ContainerInterface $container, |
16 | - ) {} |
|
16 | + ){} |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * @psalm-suppress InvalidReturnType |
20 | 20 | * @psalm-suppress InvalidReturnStatement |
21 | 21 | */ |
22 | - public function __invoke(LogRecord|array $record): array|LogRecord |
|
22 | + public function __invoke(LogRecord | array $record): array | LogRecord |
|
23 | 23 | { |
24 | 24 | $tracer = $this->container->get(TracerInterface::class); |
25 | 25 | \assert($tracer instanceof TracerInterface); |
26 | 26 | |
27 | 27 | $context = $tracer->getContext(); |
28 | 28 | |
29 | - if (!empty($context)) { |
|
29 | + if (!empty($context)){ |
|
30 | 30 | $record['extra']['telemetry'] = $context; |
31 | 31 | } |
32 | 32 |
@@ -13,7 +13,8 @@ discard block |
||
13 | 13 | { |
14 | 14 | public function __construct( |
15 | 15 | private readonly ContainerInterface $container, |
16 | - ) {} |
|
16 | + ) { |
|
17 | +} |
|
17 | 18 | |
18 | 19 | /** |
19 | 20 | * @psalm-suppress InvalidReturnType |
@@ -26,7 +27,8 @@ discard block |
||
26 | 27 | |
27 | 28 | $context = $tracer->getContext(); |
28 | 29 | |
29 | - if (!empty($context)) { |
|
30 | + if (!empty($context)) |
|
31 | + { |
|
30 | 32 | $record['extra']['telemetry'] = $context; |
31 | 33 | } |
32 | 34 |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | public function __construct( |
35 | 35 | private readonly ConfiguratorInterface $config, |
36 | - ) {} |
|
36 | + ){} |
|
37 | 37 | |
38 | 38 | public function init(BinderInterface $binder, EnvironmentInterface $env): void |
39 | 39 | { |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * @param class-string<TracerFactoryInterface>|TracerFactoryInterface|Autowire $driver |
52 | 52 | */ |
53 | - public function registerTracer(string $name, string|TracerFactoryInterface|Autowire $driver): void |
|
53 | + public function registerTracer(string $name, string | TracerFactoryInterface | Autowire $driver): void |
|
54 | 54 | { |
55 | 55 | $this->config->modify( |
56 | 56 | TelemetryConfig::CONFIG, |
@@ -33,7 +33,8 @@ |
||
33 | 33 | |
34 | 34 | public function __construct( |
35 | 35 | private readonly ConfiguratorInterface $config, |
36 | - ) {} |
|
36 | + ) { |
|
37 | +} |
|
37 | 38 | |
38 | 39 | public function init(BinderInterface $binder, EnvironmentInterface $env): void |
39 | 40 | { |
@@ -66,19 +66,19 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @throws \Throwable |
68 | 68 | */ |
69 | - public function make(string $alias, array $parameters = [], \Stringable|string|null $context = null): mixed |
|
69 | + public function make(string $alias, array $parameters = [], \Stringable | string | null $context = null): mixed |
|
70 | 70 | { |
71 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
71 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)){ |
|
72 | 72 | return $this->state->singletons[$alias]; |
73 | 73 | } |
74 | 74 | |
75 | 75 | $binding = $this->state->bindings[$alias] ?? null; |
76 | 76 | |
77 | - if ($binding === null) { |
|
77 | + if ($binding === null){ |
|
78 | 78 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
79 | 79 | } |
80 | 80 | |
81 | - try { |
|
81 | + try{ |
|
82 | 82 | $this->tracer->push( |
83 | 83 | false, |
84 | 84 | action: 'resolve from binding', |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
109 | 109 | default => $binding, |
110 | 110 | }; |
111 | - } finally { |
|
111 | + }finally{ |
|
112 | 112 | $this->state->bindings[$alias] ??= $binding; |
113 | 113 | $this->tracer->pop(true); |
114 | 114 | $this->tracer->pop(false); |
@@ -122,18 +122,18 @@ discard block |
||
122 | 122 | private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments) |
123 | 123 | { |
124 | 124 | $context = $ctx->context; |
125 | - try { |
|
125 | + try{ |
|
126 | 126 | $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class); |
127 | - } catch (\ReflectionException $e) { |
|
127 | + }catch (\ReflectionException $e){ |
|
128 | 128 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
129 | 129 | } |
130 | 130 | |
131 | 131 | $injector = $binding->injector; |
132 | 132 | |
133 | - try { |
|
133 | + try{ |
|
134 | 134 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
135 | 135 | |
136 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
136 | + if (!$injectorInstance instanceof InjectorInterface){ |
|
137 | 137 | throw new InjectionException( |
138 | 138 | \sprintf( |
139 | 139 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | static $cache = []; |
148 | 148 | $extended = $cache[$injectorInstance::class] ??= ( |
149 | 149 | static fn(\ReflectionType $type): bool => |
150 | - $type::class === \ReflectionUnionType::class || (string) $type === 'mixed' |
|
150 | + $type::class === \ReflectionUnionType::class || (string)$type === 'mixed' |
|
151 | 151 | )( |
152 | 152 | ($refMethod = new \ReflectionMethod($injectorInstance, 'createInjection')) |
153 | 153 | ->getParameters()[1]->getType() |
@@ -157,10 +157,10 @@ discard block |
||
157 | 157 | $instance = $injectorInstance->createInjection($reflection, match (true) { |
158 | 158 | $asIs => $context, |
159 | 159 | $context instanceof \ReflectionParameter => $context->getName(), |
160 | - default => (string) $context, |
|
160 | + default => (string)$context, |
|
161 | 161 | }); |
162 | 162 | |
163 | - if (!$reflection->isInstance($instance)) { |
|
163 | + if (!$reflection->isInstance($instance)){ |
|
164 | 164 | throw new InjectionException( |
165 | 165 | \sprintf( |
166 | 166 | "Invalid injection response for '%s'.", |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | } |
171 | 171 | |
172 | 172 | return $instance; |
173 | - } finally { |
|
173 | + }finally{ |
|
174 | 174 | $this->state->bindings[$ctx->class] ??= $binding; |
175 | 175 | } |
176 | 176 | } |
@@ -178,27 +178,27 @@ discard block |
||
178 | 178 | private function resolveAlias( |
179 | 179 | Config\Alias $binding, |
180 | 180 | string $alias, |
181 | - \Stringable|string|null $context, |
|
181 | + \Stringable | string | null $context, |
|
182 | 182 | array $arguments, |
183 | 183 | ): mixed { |
184 | 184 | $result = $binding->alias === $alias |
185 | 185 | ? $this->autowire( |
186 | - new Ctx(alias: $alias, class: $binding->alias, context: $context, singleton: $binding->singleton), |
|
186 | + new Ctx(alias : $alias, class : $binding->alias, context : $context, singleton : $binding->singleton), |
|
187 | 187 | $arguments, |
188 | 188 | ) |
189 | 189 | //Binding is pointing to something else |
190 | 190 | : $this->make($binding->alias, $arguments, $context); |
191 | 191 | |
192 | - if ($binding->singleton && $arguments === []) { |
|
192 | + if ($binding->singleton && $arguments === []){ |
|
193 | 193 | $this->state->singletons[$alias] = $result; |
194 | 194 | } |
195 | 195 | |
196 | 196 | return $result; |
197 | 197 | } |
198 | 198 | |
199 | - private function resolveProxy(Config\Proxy $binding, string $alias, \Stringable|string|null $context): mixed |
|
199 | + private function resolveProxy(Config\Proxy $binding, string $alias, \Stringable | string | null $context): mixed |
|
200 | 200 | { |
201 | - if ($context instanceof RetryContext) { |
|
201 | + if ($context instanceof RetryContext){ |
|
202 | 202 | return $binding->fallbackFactory === null |
203 | 203 | ? throw new RecursiveProxyException( |
204 | 204 | $alias, |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | |
210 | 210 | $result = Proxy::create(new \ReflectionClass($binding->getInterface()), $context, new Attribute\Proxy()); |
211 | 211 | |
212 | - if ($binding->singleton) { |
|
212 | + if ($binding->singleton){ |
|
213 | 213 | $this->state->singletons[$alias] = $result; |
214 | 214 | } |
215 | 215 | |
@@ -219,19 +219,19 @@ discard block |
||
219 | 219 | private function resolveShared( |
220 | 220 | Config\Shared $binding, |
221 | 221 | string $alias, |
222 | - \Stringable|string|null $context, |
|
222 | + \Stringable | string | null $context, |
|
223 | 223 | array $arguments, |
224 | 224 | ): object { |
225 | 225 | $avoidCache = $arguments !== []; |
226 | 226 | |
227 | - if ($avoidCache) { |
|
227 | + if ($avoidCache){ |
|
228 | 228 | return $this->createInstance( |
229 | 229 | new Ctx(alias: $alias, class: $binding->value::class, context: $context), |
230 | 230 | $arguments, |
231 | 231 | ); |
232 | 232 | } |
233 | 233 | |
234 | - if ($binding->singleton) { |
|
234 | + if ($binding->singleton){ |
|
235 | 235 | $this->state->singletons[$alias] = $binding->value; |
236 | 236 | } |
237 | 237 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | private function resolveAutowire( |
242 | 242 | Config\Autowire $binding, |
243 | 243 | string $alias, |
244 | - \Stringable|string|null $context, |
|
244 | + \Stringable | string | null $context, |
|
245 | 245 | array $arguments, |
246 | 246 | ): mixed { |
247 | 247 | $target = $binding->autowire->alias; |
@@ -255,17 +255,17 @@ discard block |
||
255 | 255 | } |
256 | 256 | |
257 | 257 | private function resolveFactory( |
258 | - Config\Factory|Config\DeferredFactory $binding, |
|
258 | + Config\Factory | Config\DeferredFactory $binding, |
|
259 | 259 | string $alias, |
260 | - \Stringable|string|null $context, |
|
260 | + \Stringable | string | null $context, |
|
261 | 261 | array $arguments, |
262 | 262 | ): mixed { |
263 | 263 | $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton); |
264 | - try { |
|
264 | + try{ |
|
265 | 265 | $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0 |
266 | 266 | ? ($binding->factory)() |
267 | 267 | : $this->invoker->invoke($binding->factory, $arguments); |
268 | - } catch (NotCallableException $e) { |
|
268 | + }catch (NotCallableException $e){ |
|
269 | 269 | throw new ContainerException( |
270 | 270 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
271 | 271 | $e->getCode(), |
@@ -279,24 +279,24 @@ discard block |
||
279 | 279 | private function resolveWeakReference( |
280 | 280 | Config\WeakReference $binding, |
281 | 281 | string $alias, |
282 | - \Stringable|string|null $context, |
|
282 | + \Stringable | string | null $context, |
|
283 | 283 | array $arguments, |
284 | 284 | ): ?object { |
285 | 285 | $avoidCache = $arguments !== []; |
286 | 286 | |
287 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
288 | - try { |
|
287 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)){ |
|
288 | + try{ |
|
289 | 289 | $this->tracer->push(false, alias: $alias, source: \WeakReference::class, context: $context); |
290 | 290 | |
291 | 291 | $object = $this->createInstance( |
292 | 292 | new Ctx(alias: $alias, class: $alias, context: $context), |
293 | 293 | $arguments, |
294 | 294 | ); |
295 | - if ($avoidCache) { |
|
295 | + if ($avoidCache){ |
|
296 | 296 | return $object; |
297 | 297 | } |
298 | 298 | $binding->reference = \WeakReference::create($object); |
299 | - } catch (\Throwable) { |
|
299 | + }catch (\Throwable){ |
|
300 | 300 | throw new ContainerException( |
301 | 301 | $this->tracer->combineTraceMessage( |
302 | 302 | \sprintf( |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | ), |
307 | 307 | ), |
308 | 308 | ); |
309 | - } finally { |
|
309 | + }finally{ |
|
310 | 310 | $this->tracer->pop(); |
311 | 311 | } |
312 | 312 | } |
@@ -317,23 +317,23 @@ discard block |
||
317 | 317 | private function resolveWithoutBinding( |
318 | 318 | string $alias, |
319 | 319 | array $parameters = [], |
320 | - \Stringable|string|null $context = null, |
|
320 | + \Stringable | string | null $context = null, |
|
321 | 321 | ): mixed { |
322 | 322 | $parent = $this->scope->getParentFactory(); |
323 | 323 | |
324 | - if ($parent !== null) { |
|
325 | - try { |
|
324 | + if ($parent !== null){ |
|
325 | + try{ |
|
326 | 326 | $this->tracer->push(false, ...[ |
327 | 327 | 'current scope' => $this->scope->getScopeName(), |
328 | 328 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
329 | 329 | ]); |
330 | 330 | /** @psalm-suppress TooManyArguments */ |
331 | 331 | return $parent->make($alias, $parameters, $context); |
332 | - } catch (BadScopeException $e) { |
|
333 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
332 | + }catch (BadScopeException $e){ |
|
333 | + if ($this->scope->getScopeName() !== $e->getScope()){ |
|
334 | 334 | throw $e; |
335 | 335 | } |
336 | - } catch (ContainerExceptionInterface $e) { |
|
336 | + }catch (ContainerExceptionInterface $e){ |
|
337 | 337 | $className = match (true) { |
338 | 338 | $e instanceof RecursiveProxyException => throw $e, |
339 | 339 | $e instanceof NotFoundExceptionInterface => NotFoundException::class, |
@@ -343,19 +343,19 @@ discard block |
||
343 | 343 | 'Can\'t resolve `%s`.', |
344 | 344 | $alias, |
345 | 345 | )), previous: $e); |
346 | - } finally { |
|
346 | + }finally{ |
|
347 | 347 | $this->tracer->pop(false); |
348 | 348 | } |
349 | 349 | } |
350 | 350 | |
351 | 351 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
352 | - try { |
|
352 | + try{ |
|
353 | 353 | //No direct instructions how to construct class, make is automatically |
354 | 354 | return $this->autowire( |
355 | 355 | new Ctx(alias: $alias, class: $alias, context: $context), |
356 | 356 | $parameters, |
357 | 357 | ); |
358 | - } finally { |
|
358 | + }finally{ |
|
359 | 359 | $this->tracer->pop(false); |
360 | 360 | } |
361 | 361 | } |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | && |
377 | 377 | (isset($this->state->injectors[$ctx->class]) || $this->binder->hasInjector($ctx->class)) |
378 | 378 | )) |
379 | - ) { |
|
379 | + ){ |
|
380 | 380 | throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf( |
381 | 381 | 'Can\'t resolve `%s`: undefined class or binding `%s`.', |
382 | 382 | $this->tracer->getRootAlias(), |
@@ -402,13 +402,13 @@ discard block |
||
402 | 402 | Ctx $ctx, |
403 | 403 | array $arguments, |
404 | 404 | ): object { |
405 | - if ($this->options->checkScope) { |
|
405 | + if ($this->options->checkScope){ |
|
406 | 406 | // Check scope name |
407 | 407 | $ctx->reflection = new \ReflectionClass($instance); |
408 | 408 | $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
409 | - if ($scopeName !== null) { |
|
409 | + if ($scopeName !== null){ |
|
410 | 410 | $scope = $this->scope; |
411 | - while ($scope->getScopeName() !== $scopeName) { |
|
411 | + while ($scope->getScopeName() !== $scopeName){ |
|
412 | 412 | $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class); |
413 | 413 | } |
414 | 414 | } |
@@ -437,26 +437,26 @@ discard block |
||
437 | 437 | array $arguments, |
438 | 438 | ): object { |
439 | 439 | $class = $ctx->class; |
440 | - try { |
|
440 | + try{ |
|
441 | 441 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
442 | - } catch (\ReflectionException $e) { |
|
442 | + }catch (\ReflectionException $e){ |
|
443 | 443 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Check scope name |
447 | - if ($this->options->checkScope) { |
|
447 | + if ($this->options->checkScope){ |
|
448 | 448 | $scope = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
449 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
449 | + if ($scope !== null && $scope !== $this->scope->getScopeName()){ |
|
450 | 450 | throw new BadScopeException($scope, $class); |
451 | 451 | } |
452 | 452 | } |
453 | 453 | |
454 | 454 | // We have to construct class using external injector when we know the exact context |
455 | - if ($arguments === [] && $this->binder->hasInjector($class)) { |
|
455 | + if ($arguments === [] && $this->binder->hasInjector($class)){ |
|
456 | 456 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments); |
457 | 457 | } |
458 | 458 | |
459 | - if (!$reflection->isInstantiable()) { |
|
459 | + if (!$reflection->isInstantiable()){ |
|
460 | 460 | $itIs = match (true) { |
461 | 461 | $reflection->isEnum() => 'Enum', |
462 | 462 | $reflection->isAbstract() => 'Abstract class', |
@@ -469,12 +469,12 @@ discard block |
||
469 | 469 | |
470 | 470 | $constructor = $reflection->getConstructor(); |
471 | 471 | |
472 | - if ($constructor !== null) { |
|
473 | - try { |
|
472 | + if ($constructor !== null){ |
|
473 | + try{ |
|
474 | 474 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
475 | 475 | $this->tracer->push(true); |
476 | 476 | $args = $this->resolver->resolveArguments($constructor, $arguments, $this->options->validateArguments); |
477 | - } catch (ValidationException $e) { |
|
477 | + }catch (ValidationException $e){ |
|
478 | 478 | throw new ContainerException( |
479 | 479 | $this->tracer->combineTraceMessage( |
480 | 480 | \sprintf( |
@@ -484,22 +484,22 @@ discard block |
||
484 | 484 | ), |
485 | 485 | ), |
486 | 486 | ); |
487 | - } finally { |
|
487 | + }finally{ |
|
488 | 488 | $this->tracer->pop(true); |
489 | 489 | $this->tracer->pop(false); |
490 | 490 | } |
491 | - try { |
|
491 | + try{ |
|
492 | 492 | // Using constructor with resolved arguments |
493 | 493 | $this->tracer->push(false, call: "$class::__construct", arguments: $args); |
494 | 494 | $this->tracer->push(true); |
495 | 495 | $instance = new $class(...$args); |
496 | - } catch (\TypeError $e) { |
|
496 | + }catch (\TypeError $e){ |
|
497 | 497 | throw new WrongTypeException($constructor, $e); |
498 | - } finally { |
|
498 | + }finally{ |
|
499 | 499 | $this->tracer->pop(true); |
500 | 500 | $this->tracer->pop(false); |
501 | 501 | } |
502 | - } else { |
|
502 | + }else{ |
|
503 | 503 | // No constructor specified |
504 | 504 | $instance = $reflection->newInstance(); |
505 | 505 | } |
@@ -517,13 +517,13 @@ discard block |
||
517 | 517 | $instance = $this->runInflector($instance); |
518 | 518 | |
519 | 519 | //Declarative singletons |
520 | - if ($this->isSingleton($ctx)) { |
|
520 | + if ($this->isSingleton($ctx)){ |
|
521 | 521 | $this->state->singletons[$ctx->alias] = $instance; |
522 | 522 | } |
523 | 523 | |
524 | 524 | // Register finalizer |
525 | 525 | $finalizer = $this->getFinalizer($ctx, $instance); |
526 | - if ($finalizer !== null) { |
|
526 | + if ($finalizer !== null){ |
|
527 | 527 | $this->state->finalizers[] = $finalizer; |
528 | 528 | } |
529 | 529 | |
@@ -535,12 +535,12 @@ discard block |
||
535 | 535 | */ |
536 | 536 | private function isSingleton(Ctx $ctx): bool |
537 | 537 | { |
538 | - if ($ctx->singleton === true) { |
|
538 | + if ($ctx->singleton === true){ |
|
539 | 539 | return true; |
540 | 540 | } |
541 | 541 | |
542 | 542 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
543 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
543 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)){ |
|
544 | 544 | return true; |
545 | 545 | } |
546 | 546 | |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | * @var Attribute\Finalize|null $attribute |
555 | 555 | */ |
556 | 556 | $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance(); |
557 | - if ($attribute === null) { |
|
557 | + if ($attribute === null){ |
|
558 | 558 | return null; |
559 | 559 | } |
560 | 560 | |
@@ -568,10 +568,10 @@ discard block |
||
568 | 568 | { |
569 | 569 | $scope = $this->scope; |
570 | 570 | |
571 | - while ($scope !== null) { |
|
572 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
573 | - if ($instance instanceof $class) { |
|
574 | - foreach ($inflectors as $inflector) { |
|
571 | + while ($scope !== null){ |
|
572 | + foreach ($this->state->inflectors as $class => $inflectors){ |
|
573 | + if ($instance instanceof $class){ |
|
574 | + foreach ($inflectors as $inflector){ |
|
575 | 575 | $instance = $inflector->getParametersCount() > 1 |
576 | 576 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
577 | 577 | : ($inflector->inflector)($instance); |
@@ -587,9 +587,9 @@ discard block |
||
587 | 587 | |
588 | 588 | private function validateArguments(ContextFunction $reflection, array $arguments = []): bool |
589 | 589 | { |
590 | - try { |
|
590 | + try{ |
|
591 | 591 | $this->resolver->validateArguments($reflection, $arguments); |
592 | - } catch (\Throwable) { |
|
592 | + }catch (\Throwable){ |
|
593 | 593 | return false; |
594 | 594 | } |
595 | 595 |
@@ -68,17 +68,20 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function make(string $alias, array $parameters = [], \Stringable|string|null $context = null): mixed |
70 | 70 | { |
71 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
71 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) |
|
72 | + { |
|
72 | 73 | return $this->state->singletons[$alias]; |
73 | 74 | } |
74 | 75 | |
75 | 76 | $binding = $this->state->bindings[$alias] ?? null; |
76 | 77 | |
77 | - if ($binding === null) { |
|
78 | + if ($binding === null) |
|
79 | + { |
|
78 | 80 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
79 | 81 | } |
80 | 82 | |
81 | - try { |
|
83 | + try |
|
84 | + { |
|
82 | 85 | $this->tracer->push( |
83 | 86 | false, |
84 | 87 | action: 'resolve from binding', |
@@ -108,7 +111,9 @@ discard block |
||
108 | 111 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
109 | 112 | default => $binding, |
110 | 113 | }; |
111 | - } finally { |
|
114 | + } |
|
115 | + finally |
|
116 | + { |
|
112 | 117 | $this->state->bindings[$alias] ??= $binding; |
113 | 118 | $this->tracer->pop(true); |
114 | 119 | $this->tracer->pop(false); |
@@ -122,18 +127,23 @@ discard block |
||
122 | 127 | private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments) |
123 | 128 | { |
124 | 129 | $context = $ctx->context; |
125 | - try { |
|
130 | + try |
|
131 | + { |
|
126 | 132 | $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class); |
127 | - } catch (\ReflectionException $e) { |
|
133 | + } |
|
134 | + catch (\ReflectionException $e) |
|
135 | + { |
|
128 | 136 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
129 | 137 | } |
130 | 138 | |
131 | 139 | $injector = $binding->injector; |
132 | 140 | |
133 | - try { |
|
141 | + try |
|
142 | + { |
|
134 | 143 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
135 | 144 | |
136 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
145 | + if (!$injectorInstance instanceof InjectorInterface) |
|
146 | + { |
|
137 | 147 | throw new InjectionException( |
138 | 148 | \sprintf( |
139 | 149 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -160,7 +170,8 @@ discard block |
||
160 | 170 | default => (string) $context, |
161 | 171 | }); |
162 | 172 | |
163 | - if (!$reflection->isInstance($instance)) { |
|
173 | + if (!$reflection->isInstance($instance)) |
|
174 | + { |
|
164 | 175 | throw new InjectionException( |
165 | 176 | \sprintf( |
166 | 177 | "Invalid injection response for '%s'.", |
@@ -170,7 +181,9 @@ discard block |
||
170 | 181 | } |
171 | 182 | |
172 | 183 | return $instance; |
173 | - } finally { |
|
184 | + } |
|
185 | + finally |
|
186 | + { |
|
174 | 187 | $this->state->bindings[$ctx->class] ??= $binding; |
175 | 188 | } |
176 | 189 | } |
@@ -189,7 +202,8 @@ discard block |
||
189 | 202 | //Binding is pointing to something else |
190 | 203 | : $this->make($binding->alias, $arguments, $context); |
191 | 204 | |
192 | - if ($binding->singleton && $arguments === []) { |
|
205 | + if ($binding->singleton && $arguments === []) |
|
206 | + { |
|
193 | 207 | $this->state->singletons[$alias] = $result; |
194 | 208 | } |
195 | 209 | |
@@ -198,7 +212,8 @@ discard block |
||
198 | 212 | |
199 | 213 | private function resolveProxy(Config\Proxy $binding, string $alias, \Stringable|string|null $context): mixed |
200 | 214 | { |
201 | - if ($context instanceof RetryContext) { |
|
215 | + if ($context instanceof RetryContext) |
|
216 | + { |
|
202 | 217 | return $binding->fallbackFactory === null |
203 | 218 | ? throw new RecursiveProxyException( |
204 | 219 | $alias, |
@@ -209,7 +224,8 @@ discard block |
||
209 | 224 | |
210 | 225 | $result = Proxy::create(new \ReflectionClass($binding->getInterface()), $context, new Attribute\Proxy()); |
211 | 226 | |
212 | - if ($binding->singleton) { |
|
227 | + if ($binding->singleton) |
|
228 | + { |
|
213 | 229 | $this->state->singletons[$alias] = $result; |
214 | 230 | } |
215 | 231 | |
@@ -224,14 +240,16 @@ discard block |
||
224 | 240 | ): object { |
225 | 241 | $avoidCache = $arguments !== []; |
226 | 242 | |
227 | - if ($avoidCache) { |
|
243 | + if ($avoidCache) |
|
244 | + { |
|
228 | 245 | return $this->createInstance( |
229 | 246 | new Ctx(alias: $alias, class: $binding->value::class, context: $context), |
230 | 247 | $arguments, |
231 | 248 | ); |
232 | 249 | } |
233 | 250 | |
234 | - if ($binding->singleton) { |
|
251 | + if ($binding->singleton) |
|
252 | + { |
|
235 | 253 | $this->state->singletons[$alias] = $binding->value; |
236 | 254 | } |
237 | 255 | |
@@ -261,11 +279,14 @@ discard block |
||
261 | 279 | array $arguments, |
262 | 280 | ): mixed { |
263 | 281 | $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton); |
264 | - try { |
|
282 | + try |
|
283 | + { |
|
265 | 284 | $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0 |
266 | 285 | ? ($binding->factory)() |
267 | 286 | : $this->invoker->invoke($binding->factory, $arguments); |
268 | - } catch (NotCallableException $e) { |
|
287 | + } |
|
288 | + catch (NotCallableException $e) |
|
289 | + { |
|
269 | 290 | throw new ContainerException( |
270 | 291 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
271 | 292 | $e->getCode(), |
@@ -284,19 +305,24 @@ discard block |
||
284 | 305 | ): ?object { |
285 | 306 | $avoidCache = $arguments !== []; |
286 | 307 | |
287 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
288 | - try { |
|
308 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) |
|
309 | + { |
|
310 | + try |
|
311 | + { |
|
289 | 312 | $this->tracer->push(false, alias: $alias, source: \WeakReference::class, context: $context); |
290 | 313 | |
291 | 314 | $object = $this->createInstance( |
292 | 315 | new Ctx(alias: $alias, class: $alias, context: $context), |
293 | 316 | $arguments, |
294 | 317 | ); |
295 | - if ($avoidCache) { |
|
318 | + if ($avoidCache) |
|
319 | + { |
|
296 | 320 | return $object; |
297 | 321 | } |
298 | 322 | $binding->reference = \WeakReference::create($object); |
299 | - } catch (\Throwable) { |
|
323 | + } |
|
324 | + catch (\Throwable) |
|
325 | + { |
|
300 | 326 | throw new ContainerException( |
301 | 327 | $this->tracer->combineTraceMessage( |
302 | 328 | \sprintf( |
@@ -306,7 +332,9 @@ discard block |
||
306 | 332 | ), |
307 | 333 | ), |
308 | 334 | ); |
309 | - } finally { |
|
335 | + } |
|
336 | + finally |
|
337 | + { |
|
310 | 338 | $this->tracer->pop(); |
311 | 339 | } |
312 | 340 | } |
@@ -321,19 +349,26 @@ discard block |
||
321 | 349 | ): mixed { |
322 | 350 | $parent = $this->scope->getParentFactory(); |
323 | 351 | |
324 | - if ($parent !== null) { |
|
325 | - try { |
|
352 | + if ($parent !== null) |
|
353 | + { |
|
354 | + try |
|
355 | + { |
|
326 | 356 | $this->tracer->push(false, ...[ |
327 | 357 | 'current scope' => $this->scope->getScopeName(), |
328 | 358 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
329 | 359 | ]); |
330 | 360 | /** @psalm-suppress TooManyArguments */ |
331 | 361 | return $parent->make($alias, $parameters, $context); |
332 | - } catch (BadScopeException $e) { |
|
333 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
362 | + } |
|
363 | + catch (BadScopeException $e) |
|
364 | + { |
|
365 | + if ($this->scope->getScopeName() !== $e->getScope()) |
|
366 | + { |
|
334 | 367 | throw $e; |
335 | 368 | } |
336 | - } catch (ContainerExceptionInterface $e) { |
|
369 | + } |
|
370 | + catch (ContainerExceptionInterface $e) |
|
371 | + { |
|
337 | 372 | $className = match (true) { |
338 | 373 | $e instanceof RecursiveProxyException => throw $e, |
339 | 374 | $e instanceof NotFoundExceptionInterface => NotFoundException::class, |
@@ -343,19 +378,24 @@ discard block |
||
343 | 378 | 'Can\'t resolve `%s`.', |
344 | 379 | $alias, |
345 | 380 | )), previous: $e); |
346 | - } finally { |
|
381 | + } |
|
382 | + finally |
|
383 | + { |
|
347 | 384 | $this->tracer->pop(false); |
348 | 385 | } |
349 | 386 | } |
350 | 387 | |
351 | 388 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
352 | - try { |
|
389 | + try |
|
390 | + { |
|
353 | 391 | //No direct instructions how to construct class, make is automatically |
354 | 392 | return $this->autowire( |
355 | 393 | new Ctx(alias: $alias, class: $alias, context: $context), |
356 | 394 | $parameters, |
357 | 395 | ); |
358 | - } finally { |
|
396 | + } |
|
397 | + finally |
|
398 | + { |
|
359 | 399 | $this->tracer->pop(false); |
360 | 400 | } |
361 | 401 | } |
@@ -402,13 +442,16 @@ discard block |
||
402 | 442 | Ctx $ctx, |
403 | 443 | array $arguments, |
404 | 444 | ): object { |
405 | - if ($this->options->checkScope) { |
|
445 | + if ($this->options->checkScope) |
|
446 | + { |
|
406 | 447 | // Check scope name |
407 | 448 | $ctx->reflection = new \ReflectionClass($instance); |
408 | 449 | $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
409 | - if ($scopeName !== null) { |
|
450 | + if ($scopeName !== null) |
|
451 | + { |
|
410 | 452 | $scope = $this->scope; |
411 | - while ($scope->getScopeName() !== $scopeName) { |
|
453 | + while ($scope->getScopeName() !== $scopeName) |
|
454 | + { |
|
412 | 455 | $scope = $scope->getParentScope() ?? throw new BadScopeException($scopeName, $instance::class); |
413 | 456 | } |
414 | 457 | } |
@@ -437,26 +480,33 @@ discard block |
||
437 | 480 | array $arguments, |
438 | 481 | ): object { |
439 | 482 | $class = $ctx->class; |
440 | - try { |
|
483 | + try |
|
484 | + { |
|
441 | 485 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
442 | - } catch (\ReflectionException $e) { |
|
486 | + } |
|
487 | + catch (\ReflectionException $e) |
|
488 | + { |
|
443 | 489 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
444 | 490 | } |
445 | 491 | |
446 | 492 | // Check scope name |
447 | - if ($this->options->checkScope) { |
|
493 | + if ($this->options->checkScope) |
|
494 | + { |
|
448 | 495 | $scope = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
449 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
496 | + if ($scope !== null && $scope !== $this->scope->getScopeName()) |
|
497 | + { |
|
450 | 498 | throw new BadScopeException($scope, $class); |
451 | 499 | } |
452 | 500 | } |
453 | 501 | |
454 | 502 | // We have to construct class using external injector when we know the exact context |
455 | - if ($arguments === [] && $this->binder->hasInjector($class)) { |
|
503 | + if ($arguments === [] && $this->binder->hasInjector($class)) |
|
504 | + { |
|
456 | 505 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments); |
457 | 506 | } |
458 | 507 | |
459 | - if (!$reflection->isInstantiable()) { |
|
508 | + if (!$reflection->isInstantiable()) |
|
509 | + { |
|
460 | 510 | $itIs = match (true) { |
461 | 511 | $reflection->isEnum() => 'Enum', |
462 | 512 | $reflection->isAbstract() => 'Abstract class', |
@@ -469,12 +519,16 @@ discard block |
||
469 | 519 | |
470 | 520 | $constructor = $reflection->getConstructor(); |
471 | 521 | |
472 | - if ($constructor !== null) { |
|
473 | - try { |
|
522 | + if ($constructor !== null) |
|
523 | + { |
|
524 | + try |
|
525 | + { |
|
474 | 526 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
475 | 527 | $this->tracer->push(true); |
476 | 528 | $args = $this->resolver->resolveArguments($constructor, $arguments, $this->options->validateArguments); |
477 | - } catch (ValidationException $e) { |
|
529 | + } |
|
530 | + catch (ValidationException $e) |
|
531 | + { |
|
478 | 532 | throw new ContainerException( |
479 | 533 | $this->tracer->combineTraceMessage( |
480 | 534 | \sprintf( |
@@ -484,22 +538,31 @@ discard block |
||
484 | 538 | ), |
485 | 539 | ), |
486 | 540 | ); |
487 | - } finally { |
|
541 | + } |
|
542 | + finally |
|
543 | + { |
|
488 | 544 | $this->tracer->pop(true); |
489 | 545 | $this->tracer->pop(false); |
490 | 546 | } |
491 | - try { |
|
547 | + try |
|
548 | + { |
|
492 | 549 | // Using constructor with resolved arguments |
493 | 550 | $this->tracer->push(false, call: "$class::__construct", arguments: $args); |
494 | 551 | $this->tracer->push(true); |
495 | 552 | $instance = new $class(...$args); |
496 | - } catch (\TypeError $e) { |
|
553 | + } |
|
554 | + catch (\TypeError $e) |
|
555 | + { |
|
497 | 556 | throw new WrongTypeException($constructor, $e); |
498 | - } finally { |
|
557 | + } |
|
558 | + finally |
|
559 | + { |
|
499 | 560 | $this->tracer->pop(true); |
500 | 561 | $this->tracer->pop(false); |
501 | 562 | } |
502 | - } else { |
|
563 | + } |
|
564 | + else |
|
565 | + { |
|
503 | 566 | // No constructor specified |
504 | 567 | $instance = $reflection->newInstance(); |
505 | 568 | } |
@@ -517,13 +580,15 @@ discard block |
||
517 | 580 | $instance = $this->runInflector($instance); |
518 | 581 | |
519 | 582 | //Declarative singletons |
520 | - if ($this->isSingleton($ctx)) { |
|
583 | + if ($this->isSingleton($ctx)) |
|
584 | + { |
|
521 | 585 | $this->state->singletons[$ctx->alias] = $instance; |
522 | 586 | } |
523 | 587 | |
524 | 588 | // Register finalizer |
525 | 589 | $finalizer = $this->getFinalizer($ctx, $instance); |
526 | - if ($finalizer !== null) { |
|
590 | + if ($finalizer !== null) |
|
591 | + { |
|
527 | 592 | $this->state->finalizers[] = $finalizer; |
528 | 593 | } |
529 | 594 | |
@@ -535,12 +600,14 @@ discard block |
||
535 | 600 | */ |
536 | 601 | private function isSingleton(Ctx $ctx): bool |
537 | 602 | { |
538 | - if ($ctx->singleton === true) { |
|
603 | + if ($ctx->singleton === true) |
|
604 | + { |
|
539 | 605 | return true; |
540 | 606 | } |
541 | 607 | |
542 | 608 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
543 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
609 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)) |
|
610 | + { |
|
544 | 611 | return true; |
545 | 612 | } |
546 | 613 | |
@@ -554,7 +621,8 @@ discard block |
||
554 | 621 | * @var Attribute\Finalize|null $attribute |
555 | 622 | */ |
556 | 623 | $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance(); |
557 | - if ($attribute === null) { |
|
624 | + if ($attribute === null) |
|
625 | + { |
|
558 | 626 | return null; |
559 | 627 | } |
560 | 628 | |
@@ -568,10 +636,14 @@ discard block |
||
568 | 636 | { |
569 | 637 | $scope = $this->scope; |
570 | 638 | |
571 | - while ($scope !== null) { |
|
572 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
573 | - if ($instance instanceof $class) { |
|
574 | - foreach ($inflectors as $inflector) { |
|
639 | + while ($scope !== null) |
|
640 | + { |
|
641 | + foreach ($this->state->inflectors as $class => $inflectors) |
|
642 | + { |
|
643 | + if ($instance instanceof $class) |
|
644 | + { |
|
645 | + foreach ($inflectors as $inflector) |
|
646 | + { |
|
575 | 647 | $instance = $inflector->getParametersCount() > 1 |
576 | 648 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
577 | 649 | : ($inflector->inflector)($instance); |
@@ -587,9 +659,12 @@ discard block |
||
587 | 659 | |
588 | 660 | private function validateArguments(ContextFunction $reflection, array $arguments = []): bool |
589 | 661 | { |
590 | - try { |
|
662 | + try |
|
663 | + { |
|
591 | 664 | $this->resolver->validateArguments($reflection, $arguments); |
592 | - } catch (\Throwable) { |
|
665 | + } |
|
666 | + catch (\Throwable) |
|
667 | + { |
|
593 | 668 | return false; |
594 | 669 | } |
595 | 670 |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | { |
21 | 21 | public function __construct( |
22 | 22 | private readonly ?ScopeInterface $scope = new Container(), |
23 | - ) {} |
|
23 | + ){} |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * @throws \Throwable |
@@ -28,18 +28,18 @@ discard block |
||
28 | 28 | final protected function runScope(SpanInterface $span, callable $callback): mixed |
29 | 29 | { |
30 | 30 | $container = ContainerScope::getContainer(); |
31 | - if ($container === null) { |
|
31 | + if ($container === null){ |
|
32 | 32 | return $this->scope->runScope([ |
33 | 33 | SpanInterface::class => $span, |
34 | 34 | TracerInterface::class => $this, |
35 | 35 | ], static fn(InvokerInterface $invoker): mixed => $invoker->invoke($callback)); |
36 | 36 | } |
37 | 37 | |
38 | - if ($container instanceof Container) { |
|
38 | + if ($container instanceof Container){ |
|
39 | 39 | $invoker = $container; |
40 | 40 | $binder = $container; |
41 | 41 | $scope = $container; |
42 | - } else { |
|
42 | + }else{ |
|
43 | 43 | /** @var ScopeInterface $scope */ |
44 | 44 | $scope = $container->get(ScopeInterface::class); |
45 | 45 | /** @var InvokerInterface $invoker */ |
@@ -48,28 +48,28 @@ discard block |
||
48 | 48 | $binder = $container->get(BinderInterface::class); |
49 | 49 | } |
50 | 50 | |
51 | - try { |
|
51 | + try{ |
|
52 | 52 | $prevSpan = $container->get(SpanInterface::class); |
53 | - } catch (\Throwable) { |
|
53 | + }catch (\Throwable){ |
|
54 | 54 | $prevSpan = null; |
55 | 55 | } |
56 | 56 | |
57 | 57 | /** @psalm-suppress TooManyArguments */ |
58 | 58 | $binder->bindSingleton(SpanInterface::class, $span, true); |
59 | 59 | |
60 | - try { |
|
60 | + try{ |
|
61 | 61 | /** @psalm-suppress InvalidArgument */ |
62 | 62 | return $prevSpan === null |
63 | 63 | ? $scope->runScope( |
64 | 64 | new Scope( |
65 | - bindings: [ |
|
65 | + bindings : [ |
|
66 | 66 | TracerInterface::class => $this, |
67 | 67 | ], |
68 | 68 | ), |
69 | - static fn(InvokerInterface $invoker): mixed => $invoker->invoke($callback), |
|
69 | + static fn(InvokerInterface $invoker) : mixed => $invoker->invoke($callback), |
|
70 | 70 | ) |
71 | 71 | : $invoker->invoke($callback); |
72 | - } finally { |
|
72 | + }finally{ |
|
73 | 73 | $prevSpan === null |
74 | 74 | ? $binder->removeBinding(SpanInterface::class) |
75 | 75 | : $binder->bindSingleton(SpanInterface::class, $prevSpan); |
@@ -20,7 +20,8 @@ discard block |
||
20 | 20 | { |
21 | 21 | public function __construct( |
22 | 22 | private readonly ?ScopeInterface $scope = new Container(), |
23 | - ) {} |
|
23 | + ) { |
|
24 | +} |
|
24 | 25 | |
25 | 26 | /** |
26 | 27 | * @throws \Throwable |
@@ -28,18 +29,22 @@ discard block |
||
28 | 29 | final protected function runScope(SpanInterface $span, callable $callback): mixed |
29 | 30 | { |
30 | 31 | $container = ContainerScope::getContainer(); |
31 | - if ($container === null) { |
|
32 | + if ($container === null) |
|
33 | + { |
|
32 | 34 | return $this->scope->runScope([ |
33 | 35 | SpanInterface::class => $span, |
34 | 36 | TracerInterface::class => $this, |
35 | 37 | ], static fn(InvokerInterface $invoker): mixed => $invoker->invoke($callback)); |
36 | 38 | } |
37 | 39 | |
38 | - if ($container instanceof Container) { |
|
40 | + if ($container instanceof Container) |
|
41 | + { |
|
39 | 42 | $invoker = $container; |
40 | 43 | $binder = $container; |
41 | 44 | $scope = $container; |
42 | - } else { |
|
45 | + } |
|
46 | + else |
|
47 | + { |
|
43 | 48 | /** @var ScopeInterface $scope */ |
44 | 49 | $scope = $container->get(ScopeInterface::class); |
45 | 50 | /** @var InvokerInterface $invoker */ |
@@ -48,16 +53,20 @@ discard block |
||
48 | 53 | $binder = $container->get(BinderInterface::class); |
49 | 54 | } |
50 | 55 | |
51 | - try { |
|
56 | + try |
|
57 | + { |
|
52 | 58 | $prevSpan = $container->get(SpanInterface::class); |
53 | - } catch (\Throwable) { |
|
59 | + } |
|
60 | + catch (\Throwable) |
|
61 | + { |
|
54 | 62 | $prevSpan = null; |
55 | 63 | } |
56 | 64 | |
57 | 65 | /** @psalm-suppress TooManyArguments */ |
58 | 66 | $binder->bindSingleton(SpanInterface::class, $span, true); |
59 | 67 | |
60 | - try { |
|
68 | + try |
|
69 | + { |
|
61 | 70 | /** @psalm-suppress InvalidArgument */ |
62 | 71 | return $prevSpan === null |
63 | 72 | ? $scope->runScope( |
@@ -69,7 +78,9 @@ discard block |
||
69 | 78 | static fn(InvokerInterface $invoker): mixed => $invoker->invoke($callback), |
70 | 79 | ) |
71 | 80 | : $invoker->invoke($callback); |
72 | - } finally { |
|
81 | + } |
|
82 | + finally |
|
83 | + { |
|
73 | 84 | $prevSpan === null |
74 | 85 | ? $binder->removeBinding(SpanInterface::class) |
75 | 86 | : $binder->bindSingleton(SpanInterface::class, $prevSpan); |