@@ -35,7 +35,8 @@ discard block |
||
35 | 35 | $root->invoke(static function ( |
36 | 36 | #[Proxy] MockInterface $mock, |
37 | 37 | #[Proxy(/*proxyOverloads: true*/)] EmptyInterface $empty, |
38 | - ) use ($var) { |
|
38 | + ) use ($var) |
|
39 | + { |
|
39 | 40 | /** @var MockInterfaceImpl $proxy */ |
40 | 41 | $proxy = $$var; |
41 | 42 | $proxy->bar(name: 'foo'); // Possible to run |
@@ -52,7 +53,8 @@ discard block |
||
52 | 53 | |
53 | 54 | self::expectExceptionMessageMatches('/Call to undefined method/i'); |
54 | 55 | |
55 | - $root->invoke(static function (#[Proxy] EmptyInterface $proxy) { |
|
56 | + $root->invoke(static function (#[Proxy] EmptyInterface $proxy) |
|
57 | + { |
|
56 | 58 | $proxy->bar(name: 'foo'); // Possible to run |
57 | 59 | }); |
58 | 60 | } |
@@ -67,7 +69,8 @@ discard block |
||
67 | 69 | $root->invoke(static function ( |
68 | 70 | #[Proxy] MockInterface $mock, |
69 | 71 | #[Proxy(/*proxyOverloads: true*/)] EmptyInterface $empty, |
70 | - ) use ($var) { |
|
72 | + ) use ($var) |
|
73 | + { |
|
71 | 74 | /** @var MockInterfaceImpl $proxy */ |
72 | 75 | $proxy = $$var; |
73 | 76 | self::assertSame(['foo', 'bar', 'baz', 69], $proxy->extra('foo', 'bar', 'baz', 69)); |
@@ -87,7 +90,8 @@ discard block |
||
87 | 90 | $root->invoke(static function ( |
88 | 91 | #[Proxy] MockInterface $mock, |
89 | 92 | #[Proxy(/*proxyOverloads: true*/)] EmptyInterface $empty, |
90 | - ) use ($var) { |
|
93 | + ) use ($var) |
|
94 | + { |
|
91 | 95 | /** @var MockInterfaceImpl $proxy */ |
92 | 96 | $proxy = $$var; |
93 | 97 | self::assertSame(['foo', 'bar', 'baz', 69], $proxy->extraVariadic('foo', 'bar', 'baz', 69)); |
@@ -109,7 +113,8 @@ discard block |
||
109 | 113 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
110 | 114 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
111 | 115 | |
112 | - $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) { |
|
116 | + $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) |
|
117 | + { |
|
113 | 118 | /** @var MockInterfaceImpl $proxy */ |
114 | 119 | $proxy = $$var; |
115 | 120 | $str = 'bar'; |
@@ -129,7 +134,8 @@ discard block |
||
129 | 134 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
130 | 135 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
131 | 136 | |
132 | - $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) { |
|
137 | + $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) |
|
138 | + { |
|
133 | 139 | /** @var MockInterfaceImpl $proxy */ |
134 | 140 | $proxy = $$var; |
135 | 141 | |
@@ -152,7 +158,8 @@ discard block |
||
152 | 158 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
153 | 159 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
154 | 160 | |
155 | - $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) { |
|
161 | + $root->invoke(static function (#[Proxy] MockInterface $mock, #[Proxy] EmptyInterface $empty) use ($var) |
|
162 | + { |
|
156 | 163 | /** @var MockInterfaceImpl $proxy */ |
157 | 164 | $proxy = $$var; |
158 | 165 | $str1 = 'bar'; |
@@ -193,7 +200,8 @@ discard block |
||
193 | 200 | $this->assertInstanceOf($interface, $proxy); |
194 | 201 | $this->assertNotInstanceOf(MockInterfaceImpl::class, $proxy); |
195 | 202 | |
196 | - $root->runScope(new Scope('foo'), static function (Container $container) use ($interface, $proxy) { |
|
203 | + $root->runScope(new Scope('foo'), static function (Container $container) use ($interface, $proxy) |
|
204 | + { |
|
197 | 205 | $proxy->bar(name: 'foo'); // Possible to run |
198 | 206 | self::assertSame('foo', $proxy->baz('foo', 42)); |
199 | 207 | self::assertSame(123, $proxy->qux(age: 123)); |
@@ -243,7 +251,8 @@ discard block |
||
243 | 251 | $proxy = $root->get($interface); |
244 | 252 | $this->assertInstanceOf($interface, $proxy); |
245 | 253 | |
246 | - $root->runScope(new Scope('foo'), static function () use ($proxy) { |
|
254 | + $root->runScope(new Scope('foo'), static function () use ($proxy) |
|
255 | + { |
|
247 | 256 | $proxy->bar(name: 'foo'); // Possible to run |
248 | 257 | self::assertSame('foo', $proxy->baz('foo', 42)); |
249 | 258 | self::assertSame(123, $proxy->qux(age: 123)); |
@@ -271,7 +280,8 @@ discard block |
||
271 | 280 | $proxy = $root->get($interface); |
272 | 281 | $this->assertInstanceOf($interface, $proxy); |
273 | 282 | |
274 | - $root->runScope(new Scope('foo'), static function () use ($proxy) { |
|
283 | + $root->runScope(new Scope('foo'), static function () use ($proxy) |
|
284 | + { |
|
275 | 285 | $proxy->bar(name: 'foo'); // Possible to run |
276 | 286 | self::assertSame('foo', $proxy->baz('foo', 42)); |
277 | 287 | self::assertSame(123, $proxy->qux(age: 123)); |
@@ -293,7 +303,8 @@ discard block |
||
293 | 303 | $root->getBinder('foo')->bindSingleton($interface, Stub\MockInterfaceImpl::class); |
294 | 304 | $root->bindSingleton($interface, new Config\DeprecationProxy($interface, true, 'foo', '4.0')); |
295 | 305 | |
296 | - $root->runScope(new Scope('foo'), static function (Container $container) use ($interface) { |
|
306 | + $root->runScope(new Scope('foo'), static function (Container $container) use ($interface) |
|
307 | + { |
|
297 | 308 | $proxy = $container->get($interface); |
298 | 309 | |
299 | 310 | $proxy->bar(name: 'foo'); // Possible to run |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | self::expectExceptionMessageMatches('/Call to undefined method/i'); |
54 | 54 | |
55 | - $root->invoke(static function (#[Proxy] EmptyInterface $proxy) { |
|
55 | + $root->invoke(static function (#[Proxy] EmptyInterface $proxy){ |
|
56 | 56 | $proxy->bar(name: 'foo'); // Possible to run |
57 | 57 | }); |
58 | 58 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | $proxy = $$var; |
93 | 93 | self::assertSame(['foo', 'bar', 'baz', 69], $proxy->extraVariadic('foo', 'bar', 'baz', 69)); |
94 | 94 | self::assertSame( |
95 | - ['foo' => 'foo','zap' => 'bar', 'gas' => 69], |
|
95 | + ['foo' => 'foo', 'zap' => 'bar', 'gas' => 69], |
|
96 | 96 | $proxy->extraVariadic(foo: 'foo', zap: 'bar', gas: 69), |
97 | 97 | ); |
98 | 98 | }); |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | $root->bindSingleton(MockInterface::class, Stub\MockInterfaceImpl::class); |
178 | 178 | $root->bindSingleton(EmptyInterface::class, Stub\MockInterfaceImpl::class); |
179 | 179 | |
180 | - $mock = $root->invoke(static fn(#[Proxy] MockInterface|EmptyInterface $mock) => $mock); |
|
180 | + $mock = $root->invoke(static fn(#[Proxy] MockInterface | EmptyInterface $mock) => $mock); |
|
181 | 181 | |
182 | 182 | self::assertInstanceOf(MockInterfaceImpl::class, $mock); |
183 | 183 | } |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | { |
231 | 231 | \set_error_handler(static function (int $errno, string $error) use ($interface): void { |
232 | 232 | self::assertSame( |
233 | - \sprintf('Using `%s` outside of the `foo` scope is deprecated and will be ' . |
|
233 | + \sprintf('Using `%s` outside of the `foo` scope is deprecated and will be '. |
|
234 | 234 | 'impossible in version 4.0.', $interface), |
235 | 235 | $error |
236 | 236 | ); |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | public function testDeprecationProxyConfigDontThrowIfNotConstructed(string $interface): void |
287 | 287 | { |
288 | 288 | \set_error_handler(static function (int $errno, string $error) use ($interface): void { |
289 | - self::fail('Unexpected error: ' . $error); |
|
289 | + self::fail('Unexpected error: '.$error); |
|
290 | 290 | }); |
291 | 291 | |
292 | 292 | $root = new Container(); |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | } |
307 | 307 | |
308 | 308 | #[DataProvider('invalidDeprecationProxyArgsDataProvider')] |
309 | - public function testDeprecationProxyConfigArgsRequiredException(string|null $scope, string|null $version): void |
|
309 | + public function testDeprecationProxyConfigArgsRequiredException(string | null $scope, string | null $version): void |
|
310 | 310 | { |
311 | 311 | self::expectException(\InvalidArgumentException::class); |
312 | 312 | self::expectExceptionMessage('Scope and version or custom message must be provided.'); |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | { |
319 | 319 | $proxy = new Config\Proxy(EmptyInterface::class); |
320 | 320 | |
321 | - $this->assertSame(\sprintf('Proxy to `%s`', EmptyInterface::class), (string) $proxy); |
|
321 | + $this->assertSame(\sprintf('Proxy to `%s`', EmptyInterface::class), (string)$proxy); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | public function testProxyConfigNotInterfaceException(): void |
@@ -12,11 +12,11 @@ |
||
12 | 12 | public function __construct( |
13 | 13 | string $interface, |
14 | 14 | bool $singleton = false, |
15 | - private readonly string|\BackedEnum|null $scope = null, |
|
15 | + private readonly string | \BackedEnum | null $scope = null, |
|
16 | 16 | private readonly ?string $version = null, |
17 | 17 | private readonly ?string $message = null, |
18 | - ) { |
|
19 | - if (($scope === null || $version === null) && $message === null) { |
|
18 | + ){ |
|
19 | + if (($scope === null || $version === null) && $message === null){ |
|
20 | 20 | throw new \InvalidArgumentException('Scope and version or custom message must be provided.'); |
21 | 21 | } |
22 | 22 |
@@ -16,7 +16,8 @@ |
||
16 | 16 | private readonly ?string $version = null, |
17 | 17 | private readonly ?string $message = null, |
18 | 18 | ) { |
19 | - if (($scope === null || $version === null) && $message === null) { |
|
19 | + if (($scope === null || $version === null) && $message === null) |
|
20 | + { |
|
20 | 21 | throw new \InvalidArgumentException('Scope and version or custom message must be provided.'); |
21 | 22 | } |
22 | 23 |
@@ -12,8 +12,8 @@ |
||
12 | 12 | public function __construct( |
13 | 13 | protected readonly string $interface, |
14 | 14 | public readonly bool $singleton = false, |
15 | - ) { |
|
16 | - if (!\interface_exists($interface)) { |
|
15 | + ){ |
|
16 | + if (!\interface_exists($interface)){ |
|
17 | 17 | throw new \InvalidArgumentException(\sprintf('Interface `%s` does not exist.', $interface)); |
18 | 18 | } |
19 | 19 | } |
@@ -13,7 +13,8 @@ |
||
13 | 13 | protected readonly string $interface, |
14 | 14 | public readonly bool $singleton = false, |
15 | 15 | ) { |
16 | - if (!\interface_exists($interface)) { |
|
16 | + if (!\interface_exists($interface)) |
|
17 | + { |
|
17 | 18 | throw new \InvalidArgumentException(\sprintf('Interface `%s` does not exist.', $interface)); |
18 | 19 | } |
19 | 20 | } |
@@ -63,19 +63,19 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @throws \Throwable |
65 | 65 | */ |
66 | - public function make(string $alias, array $parameters = [], Stringable|string|null $context = null): mixed |
|
66 | + public function make(string $alias, array $parameters = [], Stringable | string | null $context = null): mixed |
|
67 | 67 | { |
68 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
68 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)){ |
|
69 | 69 | return $this->state->singletons[$alias]; |
70 | 70 | } |
71 | 71 | |
72 | 72 | $binding = $this->state->bindings[$alias] ?? null; |
73 | 73 | |
74 | - if ($binding === null) { |
|
74 | + if ($binding === null){ |
|
75 | 75 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
76 | 76 | } |
77 | 77 | |
78 | - try { |
|
78 | + try{ |
|
79 | 79 | $this->tracer->push( |
80 | 80 | false, |
81 | 81 | action: 'resolve from binding', |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
106 | 106 | default => $binding, |
107 | 107 | }; |
108 | - } finally { |
|
108 | + }finally{ |
|
109 | 109 | $this->state->bindings[$alias] ??= $binding; |
110 | 110 | $this->tracer->pop(true); |
111 | 111 | $this->tracer->pop(false); |
@@ -119,18 +119,18 @@ discard block |
||
119 | 119 | private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments) |
120 | 120 | { |
121 | 121 | $context = $ctx->context; |
122 | - try { |
|
122 | + try{ |
|
123 | 123 | $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class); |
124 | - } catch (\ReflectionException $e) { |
|
124 | + }catch (\ReflectionException $e){ |
|
125 | 125 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
126 | 126 | } |
127 | 127 | |
128 | 128 | $injector = $binding->injector; |
129 | 129 | |
130 | - try { |
|
130 | + try{ |
|
131 | 131 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
132 | 132 | |
133 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
133 | + if (!$injectorInstance instanceof InjectorInterface){ |
|
134 | 134 | throw new InjectionException( |
135 | 135 | \sprintf( |
136 | 136 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | default => (string)$context, |
158 | 158 | }); |
159 | 159 | |
160 | - if (!$reflection->isInstance($instance)) { |
|
160 | + if (!$reflection->isInstance($instance)){ |
|
161 | 161 | throw new InjectionException( |
162 | 162 | \sprintf( |
163 | 163 | "Invalid injection response for '%s'.", |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | } |
168 | 168 | |
169 | 169 | return $instance; |
170 | - } finally { |
|
170 | + }finally{ |
|
171 | 171 | $this->state->bindings[$ctx->class] ??= $binding; |
172 | 172 | } |
173 | 173 | } |
@@ -175,29 +175,29 @@ discard block |
||
175 | 175 | private function resolveAlias( |
176 | 176 | Config\Alias $binding, |
177 | 177 | string $alias, |
178 | - Stringable|string|null $context, |
|
178 | + Stringable | string | null $context, |
|
179 | 179 | array $arguments, |
180 | 180 | ): mixed { |
181 | 181 | $result = $binding->alias === $alias |
182 | 182 | ? $this->autowire( |
183 | - new Ctx(alias: $alias, class: $binding->alias, context: $context, singleton: $binding->singleton), |
|
183 | + new Ctx(alias : $alias, class : $binding->alias, context : $context, singleton : $binding->singleton), |
|
184 | 184 | $arguments, |
185 | 185 | ) |
186 | 186 | //Binding is pointing to something else |
187 | 187 | : $this->make($binding->alias, $arguments, $context); |
188 | 188 | |
189 | - if ($binding->singleton && $arguments === []) { |
|
189 | + if ($binding->singleton && $arguments === []){ |
|
190 | 190 | $this->state->singletons[$alias] = $result; |
191 | 191 | } |
192 | 192 | |
193 | 193 | return $result; |
194 | 194 | } |
195 | 195 | |
196 | - private function resolveProxy(Config\Proxy $binding, string $alias, Stringable|string|null $context): mixed |
|
196 | + private function resolveProxy(Config\Proxy $binding, string $alias, Stringable | string | null $context): mixed |
|
197 | 197 | { |
198 | 198 | $result = Proxy::create(new \ReflectionClass($binding->getInterface()), $context, new Attribute\Proxy()); |
199 | 199 | |
200 | - if ($binding->singleton) { |
|
200 | + if ($binding->singleton){ |
|
201 | 201 | $this->state->singletons[$alias] = $result; |
202 | 202 | } |
203 | 203 | |
@@ -207,13 +207,13 @@ discard block |
||
207 | 207 | private function resolveShared( |
208 | 208 | Config\Shared $binding, |
209 | 209 | string $alias, |
210 | - Stringable|string|null $context, |
|
210 | + Stringable | string | null $context, |
|
211 | 211 | array $arguments, |
212 | 212 | ): object { |
213 | 213 | $avoidCache = $arguments !== []; |
214 | 214 | return $avoidCache |
215 | 215 | ? $this->createInstance( |
216 | - new Ctx(alias: $alias, class: $binding->value::class, context: $context), |
|
216 | + new Ctx(alias : $alias, class : $binding->value::class, context : $context), |
|
217 | 217 | $arguments, |
218 | 218 | ) |
219 | 219 | : $binding->value; |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | private function resolveAutowire( |
223 | 223 | Config\Autowire $binding, |
224 | 224 | string $alias, |
225 | - Stringable|string|null $context, |
|
225 | + Stringable | string | null $context, |
|
226 | 226 | array $arguments, |
227 | 227 | ): mixed { |
228 | 228 | $instance = $binding->autowire->resolve($this, $arguments); |
@@ -232,17 +232,17 @@ discard block |
||
232 | 232 | } |
233 | 233 | |
234 | 234 | private function resolveFactory( |
235 | - Config\Factory|Config\DeferredFactory $binding, |
|
235 | + Config\Factory | Config\DeferredFactory $binding, |
|
236 | 236 | string $alias, |
237 | - Stringable|string|null $context, |
|
237 | + Stringable | string | null $context, |
|
238 | 238 | array $arguments, |
239 | 239 | ): mixed { |
240 | 240 | $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton); |
241 | - try { |
|
241 | + try{ |
|
242 | 242 | $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0 |
243 | 243 | ? ($binding->factory)() |
244 | 244 | : $this->invoker->invoke($binding->factory, $arguments); |
245 | - } catch (NotCallableException $e) { |
|
245 | + }catch (NotCallableException $e){ |
|
246 | 246 | throw new ContainerException( |
247 | 247 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
248 | 248 | $e->getCode(), |
@@ -256,24 +256,24 @@ discard block |
||
256 | 256 | private function resolveWeakReference( |
257 | 257 | Config\WeakReference $binding, |
258 | 258 | string $alias, |
259 | - Stringable|string|null $context, |
|
259 | + Stringable | string | null $context, |
|
260 | 260 | array $arguments, |
261 | 261 | ): ?object { |
262 | 262 | $avoidCache = $arguments !== []; |
263 | 263 | |
264 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
265 | - try { |
|
264 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)){ |
|
265 | + try{ |
|
266 | 266 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
267 | 267 | |
268 | 268 | $object = $this->createInstance( |
269 | 269 | new Ctx(alias: $alias, class: $alias, context: $context), |
270 | 270 | $arguments, |
271 | 271 | ); |
272 | - if ($avoidCache) { |
|
272 | + if ($avoidCache){ |
|
273 | 273 | return $object; |
274 | 274 | } |
275 | 275 | $binding->reference = WeakReference::create($object); |
276 | - } catch (\Throwable) { |
|
276 | + }catch (\Throwable){ |
|
277 | 277 | throw new ContainerException( |
278 | 278 | $this->tracer->combineTraceMessage( |
279 | 279 | \sprintf( |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | ) |
284 | 284 | ) |
285 | 285 | ); |
286 | - } finally { |
|
286 | + }finally{ |
|
287 | 287 | $this->tracer->pop(); |
288 | 288 | } |
289 | 289 | } |
@@ -294,23 +294,23 @@ discard block |
||
294 | 294 | private function resolveWithoutBinding( |
295 | 295 | string $alias, |
296 | 296 | array $parameters = [], |
297 | - Stringable|string|null $context = null |
|
297 | + Stringable | string | null $context = null |
|
298 | 298 | ): mixed { |
299 | 299 | $parent = $this->scope->getParentFactory(); |
300 | 300 | |
301 | - if ($parent !== null) { |
|
302 | - try { |
|
301 | + if ($parent !== null){ |
|
302 | + try{ |
|
303 | 303 | $this->tracer->push(false, ...[ |
304 | 304 | 'current scope' => $this->scope->getScopeName(), |
305 | 305 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
306 | 306 | ]); |
307 | 307 | /** @psalm-suppress TooManyArguments */ |
308 | 308 | return $parent->make($alias, $parameters, $context); |
309 | - } catch (BadScopeException $e) { |
|
310 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
309 | + }catch (BadScopeException $e){ |
|
310 | + if ($this->scope->getScopeName() !== $e->getScope()){ |
|
311 | 311 | throw $e; |
312 | 312 | } |
313 | - } catch (ContainerExceptionInterface $e) { |
|
313 | + }catch (ContainerExceptionInterface $e){ |
|
314 | 314 | $className = match (true) { |
315 | 315 | $e instanceof NotFoundException => NotFoundException::class, |
316 | 316 | default => ContainerException::class, |
@@ -319,19 +319,19 @@ discard block |
||
319 | 319 | 'Can\'t resolve `%s`.', |
320 | 320 | $alias, |
321 | 321 | )), previous: $e); |
322 | - } finally { |
|
322 | + }finally{ |
|
323 | 323 | $this->tracer->pop(false); |
324 | 324 | } |
325 | 325 | } |
326 | 326 | |
327 | 327 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
328 | - try { |
|
328 | + try{ |
|
329 | 329 | //No direct instructions how to construct class, make is automatically |
330 | 330 | return $this->autowire( |
331 | 331 | new Ctx(alias: $alias, class: $alias, context: $context), |
332 | 332 | $parameters, |
333 | 333 | ); |
334 | - } finally { |
|
334 | + }finally{ |
|
335 | 335 | $this->tracer->pop(false); |
336 | 336 | } |
337 | 337 | } |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | && |
353 | 353 | (isset($this->state->injectors[$ctx->class]) || $this->binder->hasInjector($ctx->class)) |
354 | 354 | )) |
355 | - ) { |
|
355 | + ){ |
|
356 | 356 | throw new NotFoundException($this->tracer->combineTraceMessage(\sprintf( |
357 | 357 | 'Can\'t resolve `%s`: undefined class or binding `%s`.', |
358 | 358 | $this->tracer->getRootAlias(), |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | // Check scope name |
382 | 382 | $ctx->reflection = new \ReflectionClass($instance); |
383 | 383 | $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
384 | - if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) { |
|
384 | + if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()){ |
|
385 | 385 | throw new BadScopeException($scopeName, $instance::class); |
386 | 386 | } |
387 | 387 | |
@@ -408,24 +408,24 @@ discard block |
||
408 | 408 | array $arguments, |
409 | 409 | ): object { |
410 | 410 | $class = $ctx->class; |
411 | - try { |
|
411 | + try{ |
|
412 | 412 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
413 | - } catch (\ReflectionException $e) { |
|
413 | + }catch (\ReflectionException $e){ |
|
414 | 414 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
415 | 415 | } |
416 | 416 | |
417 | 417 | // Check scope name |
418 | 418 | $scope = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
419 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
419 | + if ($scope !== null && $scope !== $this->scope->getScopeName()){ |
|
420 | 420 | throw new BadScopeException($scope, $class); |
421 | 421 | } |
422 | 422 | |
423 | 423 | // We have to construct class using external injector when we know the exact context |
424 | - if ($arguments === [] && $this->binder->hasInjector($class)) { |
|
424 | + if ($arguments === [] && $this->binder->hasInjector($class)){ |
|
425 | 425 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments); |
426 | 426 | } |
427 | 427 | |
428 | - if (!$reflection->isInstantiable()) { |
|
428 | + if (!$reflection->isInstantiable()){ |
|
429 | 429 | $itIs = match (true) { |
430 | 430 | $reflection->isEnum() => 'Enum', |
431 | 431 | $reflection->isAbstract() => 'Abstract class', |
@@ -438,12 +438,12 @@ discard block |
||
438 | 438 | |
439 | 439 | $constructor = $reflection->getConstructor(); |
440 | 440 | |
441 | - if ($constructor !== null) { |
|
442 | - try { |
|
441 | + if ($constructor !== null){ |
|
442 | + try{ |
|
443 | 443 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
444 | 444 | $this->tracer->push(true); |
445 | 445 | $args = $this->resolver->resolveArguments($constructor, $arguments); |
446 | - } catch (ValidationException $e) { |
|
446 | + }catch (ValidationException $e){ |
|
447 | 447 | throw new ContainerException( |
448 | 448 | $this->tracer->combineTraceMessage( |
449 | 449 | \sprintf( |
@@ -453,22 +453,22 @@ discard block |
||
453 | 453 | ) |
454 | 454 | ), |
455 | 455 | ); |
456 | - } finally { |
|
456 | + }finally{ |
|
457 | 457 | $this->tracer->pop(true); |
458 | 458 | $this->tracer->pop(false); |
459 | 459 | } |
460 | - try { |
|
460 | + try{ |
|
461 | 461 | // Using constructor with resolved arguments |
462 | 462 | $this->tracer->push(false, call: "$class::__construct", arguments: $args); |
463 | 463 | $this->tracer->push(true); |
464 | 464 | $instance = new $class(...$args); |
465 | - } catch (\TypeError $e) { |
|
465 | + }catch (\TypeError $e){ |
|
466 | 466 | throw new WrongTypeException($constructor, $e); |
467 | - } finally { |
|
467 | + }finally{ |
|
468 | 468 | $this->tracer->pop(true); |
469 | 469 | $this->tracer->pop(false); |
470 | 470 | } |
471 | - } else { |
|
471 | + }else{ |
|
472 | 472 | // No constructor specified |
473 | 473 | $instance = $reflection->newInstance(); |
474 | 474 | } |
@@ -486,13 +486,13 @@ discard block |
||
486 | 486 | $instance = $this->runInflector($instance); |
487 | 487 | |
488 | 488 | //Declarative singletons |
489 | - if ($this->isSingleton($ctx)) { |
|
489 | + if ($this->isSingleton($ctx)){ |
|
490 | 490 | $this->state->singletons[$ctx->alias] = $instance; |
491 | 491 | } |
492 | 492 | |
493 | 493 | // Register finalizer |
494 | 494 | $finalizer = $this->getFinalizer($ctx, $instance); |
495 | - if ($finalizer !== null) { |
|
495 | + if ($finalizer !== null){ |
|
496 | 496 | $this->state->finalizers[] = $finalizer; |
497 | 497 | } |
498 | 498 | |
@@ -504,12 +504,12 @@ discard block |
||
504 | 504 | */ |
505 | 505 | private function isSingleton(Ctx $ctx): bool |
506 | 506 | { |
507 | - if ($ctx->singleton === true) { |
|
507 | + if ($ctx->singleton === true){ |
|
508 | 508 | return true; |
509 | 509 | } |
510 | 510 | |
511 | 511 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
512 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
512 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)){ |
|
513 | 513 | return true; |
514 | 514 | } |
515 | 515 | |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | * @var Attribute\Finalize|null $attribute |
524 | 524 | */ |
525 | 525 | $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance(); |
526 | - if ($attribute === null) { |
|
526 | + if ($attribute === null){ |
|
527 | 527 | return null; |
528 | 528 | } |
529 | 529 | |
@@ -537,10 +537,10 @@ discard block |
||
537 | 537 | { |
538 | 538 | $scope = $this->scope; |
539 | 539 | |
540 | - while ($scope !== null) { |
|
541 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
542 | - if ($instance instanceof $class) { |
|
543 | - foreach ($inflectors as $inflector) { |
|
540 | + while ($scope !== null){ |
|
541 | + foreach ($this->state->inflectors as $class => $inflectors){ |
|
542 | + if ($instance instanceof $class){ |
|
543 | + foreach ($inflectors as $inflector){ |
|
544 | 544 | $instance = $inflector->getParametersCount() > 1 |
545 | 545 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
546 | 546 | : ($inflector->inflector)($instance); |
@@ -556,9 +556,9 @@ discard block |
||
556 | 556 | |
557 | 557 | private function validateArguments(ContextFunction $reflection, array $arguments = []): bool |
558 | 558 | { |
559 | - try { |
|
559 | + try{ |
|
560 | 560 | $this->resolver->validateArguments($reflection, $arguments); |
561 | - } catch (\Throwable) { |
|
561 | + }catch (\Throwable){ |
|
562 | 562 | return false; |
563 | 563 | } |
564 | 564 |
@@ -65,17 +65,20 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function make(string $alias, array $parameters = [], Stringable|string|null $context = null): mixed |
67 | 67 | { |
68 | - if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) { |
|
68 | + if ($parameters === [] && \array_key_exists($alias, $this->state->singletons)) |
|
69 | + { |
|
69 | 70 | return $this->state->singletons[$alias]; |
70 | 71 | } |
71 | 72 | |
72 | 73 | $binding = $this->state->bindings[$alias] ?? null; |
73 | 74 | |
74 | - if ($binding === null) { |
|
75 | + if ($binding === null) |
|
76 | + { |
|
75 | 77 | return $this->resolveWithoutBinding($alias, $parameters, $context); |
76 | 78 | } |
77 | 79 | |
78 | - try { |
|
80 | + try |
|
81 | + { |
|
79 | 82 | $this->tracer->push( |
80 | 83 | false, |
81 | 84 | action: 'resolve from binding', |
@@ -105,7 +108,9 @@ discard block |
||
105 | 108 | ->resolveWeakReference($binding, $alias, $context, $parameters), |
106 | 109 | default => $binding, |
107 | 110 | }; |
108 | - } finally { |
|
111 | + } |
|
112 | + finally |
|
113 | + { |
|
109 | 114 | $this->state->bindings[$alias] ??= $binding; |
110 | 115 | $this->tracer->pop(true); |
111 | 116 | $this->tracer->pop(false); |
@@ -119,18 +124,23 @@ discard block |
||
119 | 124 | private function resolveInjector(Config\Injectable $binding, Ctx $ctx, array $arguments) |
120 | 125 | { |
121 | 126 | $context = $ctx->context; |
122 | - try { |
|
127 | + try |
|
128 | + { |
|
123 | 129 | $reflection = $ctx->reflection ??= new \ReflectionClass($ctx->class); |
124 | - } catch (\ReflectionException $e) { |
|
130 | + } |
|
131 | + catch (\ReflectionException $e) |
|
132 | + { |
|
125 | 133 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
126 | 134 | } |
127 | 135 | |
128 | 136 | $injector = $binding->injector; |
129 | 137 | |
130 | - try { |
|
138 | + try |
|
139 | + { |
|
131 | 140 | $injectorInstance = \is_object($injector) ? $injector : $this->container->get($injector); |
132 | 141 | |
133 | - if (!$injectorInstance instanceof InjectorInterface) { |
|
142 | + if (!$injectorInstance instanceof InjectorInterface) |
|
143 | + { |
|
134 | 144 | throw new InjectionException( |
135 | 145 | \sprintf( |
136 | 146 | "Class '%s' must be an instance of InjectorInterface for '%s'.", |
@@ -157,7 +167,8 @@ discard block |
||
157 | 167 | default => (string)$context, |
158 | 168 | }); |
159 | 169 | |
160 | - if (!$reflection->isInstance($instance)) { |
|
170 | + if (!$reflection->isInstance($instance)) |
|
171 | + { |
|
161 | 172 | throw new InjectionException( |
162 | 173 | \sprintf( |
163 | 174 | "Invalid injection response for '%s'.", |
@@ -167,7 +178,9 @@ discard block |
||
167 | 178 | } |
168 | 179 | |
169 | 180 | return $instance; |
170 | - } finally { |
|
181 | + } |
|
182 | + finally |
|
183 | + { |
|
171 | 184 | $this->state->bindings[$ctx->class] ??= $binding; |
172 | 185 | } |
173 | 186 | } |
@@ -186,7 +199,8 @@ discard block |
||
186 | 199 | //Binding is pointing to something else |
187 | 200 | : $this->make($binding->alias, $arguments, $context); |
188 | 201 | |
189 | - if ($binding->singleton && $arguments === []) { |
|
202 | + if ($binding->singleton && $arguments === []) |
|
203 | + { |
|
190 | 204 | $this->state->singletons[$alias] = $result; |
191 | 205 | } |
192 | 206 | |
@@ -197,7 +211,8 @@ discard block |
||
197 | 211 | { |
198 | 212 | $result = Proxy::create(new \ReflectionClass($binding->getInterface()), $context, new Attribute\Proxy()); |
199 | 213 | |
200 | - if ($binding->singleton) { |
|
214 | + if ($binding->singleton) |
|
215 | + { |
|
201 | 216 | $this->state->singletons[$alias] = $result; |
202 | 217 | } |
203 | 218 | |
@@ -238,11 +253,14 @@ discard block |
||
238 | 253 | array $arguments, |
239 | 254 | ): mixed { |
240 | 255 | $ctx = new Ctx(alias: $alias, class: $alias, context: $context, singleton: $binding->singleton); |
241 | - try { |
|
256 | + try |
|
257 | + { |
|
242 | 258 | $instance = $binding::class === Config\Factory::class && $binding->getParametersCount() === 0 |
243 | 259 | ? ($binding->factory)() |
244 | 260 | : $this->invoker->invoke($binding->factory, $arguments); |
245 | - } catch (NotCallableException $e) { |
|
261 | + } |
|
262 | + catch (NotCallableException $e) |
|
263 | + { |
|
246 | 264 | throw new ContainerException( |
247 | 265 | $this->tracer->combineTraceMessage(\sprintf('Invalid binding for `%s`.', $ctx->alias)), |
248 | 266 | $e->getCode(), |
@@ -261,19 +279,24 @@ discard block |
||
261 | 279 | ): ?object { |
262 | 280 | $avoidCache = $arguments !== []; |
263 | 281 | |
264 | - if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) { |
|
265 | - try { |
|
282 | + if (($avoidCache || $binding->reference->get() === null) && \class_exists($alias)) |
|
283 | + { |
|
284 | + try |
|
285 | + { |
|
266 | 286 | $this->tracer->push(false, alias: $alias, source: WeakReference::class, context: $context); |
267 | 287 | |
268 | 288 | $object = $this->createInstance( |
269 | 289 | new Ctx(alias: $alias, class: $alias, context: $context), |
270 | 290 | $arguments, |
271 | 291 | ); |
272 | - if ($avoidCache) { |
|
292 | + if ($avoidCache) |
|
293 | + { |
|
273 | 294 | return $object; |
274 | 295 | } |
275 | 296 | $binding->reference = WeakReference::create($object); |
276 | - } catch (\Throwable) { |
|
297 | + } |
|
298 | + catch (\Throwable) |
|
299 | + { |
|
277 | 300 | throw new ContainerException( |
278 | 301 | $this->tracer->combineTraceMessage( |
279 | 302 | \sprintf( |
@@ -283,7 +306,9 @@ discard block |
||
283 | 306 | ) |
284 | 307 | ) |
285 | 308 | ); |
286 | - } finally { |
|
309 | + } |
|
310 | + finally |
|
311 | + { |
|
287 | 312 | $this->tracer->pop(); |
288 | 313 | } |
289 | 314 | } |
@@ -298,19 +323,26 @@ discard block |
||
298 | 323 | ): mixed { |
299 | 324 | $parent = $this->scope->getParentFactory(); |
300 | 325 | |
301 | - if ($parent !== null) { |
|
302 | - try { |
|
326 | + if ($parent !== null) |
|
327 | + { |
|
328 | + try |
|
329 | + { |
|
303 | 330 | $this->tracer->push(false, ...[ |
304 | 331 | 'current scope' => $this->scope->getScopeName(), |
305 | 332 | 'jump to parent scope' => $this->scope->getParentScope()->getScopeName(), |
306 | 333 | ]); |
307 | 334 | /** @psalm-suppress TooManyArguments */ |
308 | 335 | return $parent->make($alias, $parameters, $context); |
309 | - } catch (BadScopeException $e) { |
|
310 | - if ($this->scope->getScopeName() !== $e->getScope()) { |
|
336 | + } |
|
337 | + catch (BadScopeException $e) |
|
338 | + { |
|
339 | + if ($this->scope->getScopeName() !== $e->getScope()) |
|
340 | + { |
|
311 | 341 | throw $e; |
312 | 342 | } |
313 | - } catch (ContainerExceptionInterface $e) { |
|
343 | + } |
|
344 | + catch (ContainerExceptionInterface $e) |
|
345 | + { |
|
314 | 346 | $className = match (true) { |
315 | 347 | $e instanceof NotFoundException => NotFoundException::class, |
316 | 348 | default => ContainerException::class, |
@@ -319,19 +351,24 @@ discard block |
||
319 | 351 | 'Can\'t resolve `%s`.', |
320 | 352 | $alias, |
321 | 353 | )), previous: $e); |
322 | - } finally { |
|
354 | + } |
|
355 | + finally |
|
356 | + { |
|
323 | 357 | $this->tracer->pop(false); |
324 | 358 | } |
325 | 359 | } |
326 | 360 | |
327 | 361 | $this->tracer->push(false, action: 'autowire', alias: $alias, context: $context); |
328 | - try { |
|
362 | + try |
|
363 | + { |
|
329 | 364 | //No direct instructions how to construct class, make is automatically |
330 | 365 | return $this->autowire( |
331 | 366 | new Ctx(alias: $alias, class: $alias, context: $context), |
332 | 367 | $parameters, |
333 | 368 | ); |
334 | - } finally { |
|
369 | + } |
|
370 | + finally |
|
371 | + { |
|
335 | 372 | $this->tracer->pop(false); |
336 | 373 | } |
337 | 374 | } |
@@ -381,7 +418,8 @@ discard block |
||
381 | 418 | // Check scope name |
382 | 419 | $ctx->reflection = new \ReflectionClass($instance); |
383 | 420 | $scopeName = ($ctx->reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
384 | - if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) { |
|
421 | + if ($scopeName !== null && $scopeName !== $this->scope->getScopeName()) |
|
422 | + { |
|
385 | 423 | throw new BadScopeException($scopeName, $instance::class); |
386 | 424 | } |
387 | 425 | |
@@ -408,24 +446,30 @@ discard block |
||
408 | 446 | array $arguments, |
409 | 447 | ): object { |
410 | 448 | $class = $ctx->class; |
411 | - try { |
|
449 | + try |
|
450 | + { |
|
412 | 451 | $ctx->reflection = $reflection = new \ReflectionClass($class); |
413 | - } catch (\ReflectionException $e) { |
|
452 | + } |
|
453 | + catch (\ReflectionException $e) |
|
454 | + { |
|
414 | 455 | throw new ContainerException($e->getMessage(), $e->getCode(), $e); |
415 | 456 | } |
416 | 457 | |
417 | 458 | // Check scope name |
418 | 459 | $scope = ($reflection->getAttributes(Attribute\Scope::class)[0] ?? null)?->newInstance()->name; |
419 | - if ($scope !== null && $scope !== $this->scope->getScopeName()) { |
|
460 | + if ($scope !== null && $scope !== $this->scope->getScopeName()) |
|
461 | + { |
|
420 | 462 | throw new BadScopeException($scope, $class); |
421 | 463 | } |
422 | 464 | |
423 | 465 | // We have to construct class using external injector when we know the exact context |
424 | - if ($arguments === [] && $this->binder->hasInjector($class)) { |
|
466 | + if ($arguments === [] && $this->binder->hasInjector($class)) |
|
467 | + { |
|
425 | 468 | return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments); |
426 | 469 | } |
427 | 470 | |
428 | - if (!$reflection->isInstantiable()) { |
|
471 | + if (!$reflection->isInstantiable()) |
|
472 | + { |
|
429 | 473 | $itIs = match (true) { |
430 | 474 | $reflection->isEnum() => 'Enum', |
431 | 475 | $reflection->isAbstract() => 'Abstract class', |
@@ -438,12 +482,16 @@ discard block |
||
438 | 482 | |
439 | 483 | $constructor = $reflection->getConstructor(); |
440 | 484 | |
441 | - if ($constructor !== null) { |
|
442 | - try { |
|
485 | + if ($constructor !== null) |
|
486 | + { |
|
487 | + try |
|
488 | + { |
|
443 | 489 | $this->tracer->push(false, action: 'resolve arguments', signature: $constructor); |
444 | 490 | $this->tracer->push(true); |
445 | 491 | $args = $this->resolver->resolveArguments($constructor, $arguments); |
446 | - } catch (ValidationException $e) { |
|
492 | + } |
|
493 | + catch (ValidationException $e) |
|
494 | + { |
|
447 | 495 | throw new ContainerException( |
448 | 496 | $this->tracer->combineTraceMessage( |
449 | 497 | \sprintf( |
@@ -453,22 +501,31 @@ discard block |
||
453 | 501 | ) |
454 | 502 | ), |
455 | 503 | ); |
456 | - } finally { |
|
504 | + } |
|
505 | + finally |
|
506 | + { |
|
457 | 507 | $this->tracer->pop(true); |
458 | 508 | $this->tracer->pop(false); |
459 | 509 | } |
460 | - try { |
|
510 | + try |
|
511 | + { |
|
461 | 512 | // Using constructor with resolved arguments |
462 | 513 | $this->tracer->push(false, call: "$class::__construct", arguments: $args); |
463 | 514 | $this->tracer->push(true); |
464 | 515 | $instance = new $class(...$args); |
465 | - } catch (\TypeError $e) { |
|
516 | + } |
|
517 | + catch (\TypeError $e) |
|
518 | + { |
|
466 | 519 | throw new WrongTypeException($constructor, $e); |
467 | - } finally { |
|
520 | + } |
|
521 | + finally |
|
522 | + { |
|
468 | 523 | $this->tracer->pop(true); |
469 | 524 | $this->tracer->pop(false); |
470 | 525 | } |
471 | - } else { |
|
526 | + } |
|
527 | + else |
|
528 | + { |
|
472 | 529 | // No constructor specified |
473 | 530 | $instance = $reflection->newInstance(); |
474 | 531 | } |
@@ -486,13 +543,15 @@ discard block |
||
486 | 543 | $instance = $this->runInflector($instance); |
487 | 544 | |
488 | 545 | //Declarative singletons |
489 | - if ($this->isSingleton($ctx)) { |
|
546 | + if ($this->isSingleton($ctx)) |
|
547 | + { |
|
490 | 548 | $this->state->singletons[$ctx->alias] = $instance; |
491 | 549 | } |
492 | 550 | |
493 | 551 | // Register finalizer |
494 | 552 | $finalizer = $this->getFinalizer($ctx, $instance); |
495 | - if ($finalizer !== null) { |
|
553 | + if ($finalizer !== null) |
|
554 | + { |
|
496 | 555 | $this->state->finalizers[] = $finalizer; |
497 | 556 | } |
498 | 557 | |
@@ -504,12 +563,14 @@ discard block |
||
504 | 563 | */ |
505 | 564 | private function isSingleton(Ctx $ctx): bool |
506 | 565 | { |
507 | - if ($ctx->singleton === true) { |
|
566 | + if ($ctx->singleton === true) |
|
567 | + { |
|
508 | 568 | return true; |
509 | 569 | } |
510 | 570 | |
511 | 571 | /** @psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9489 */ |
512 | - if ($ctx->reflection->implementsInterface(SingletonInterface::class)) { |
|
572 | + if ($ctx->reflection->implementsInterface(SingletonInterface::class)) |
|
573 | + { |
|
513 | 574 | return true; |
514 | 575 | } |
515 | 576 | |
@@ -523,7 +584,8 @@ discard block |
||
523 | 584 | * @var Attribute\Finalize|null $attribute |
524 | 585 | */ |
525 | 586 | $attribute = ($ctx->reflection->getAttributes(Attribute\Finalize::class)[0] ?? null)?->newInstance(); |
526 | - if ($attribute === null) { |
|
587 | + if ($attribute === null) |
|
588 | + { |
|
527 | 589 | return null; |
528 | 590 | } |
529 | 591 | |
@@ -537,10 +599,14 @@ discard block |
||
537 | 599 | { |
538 | 600 | $scope = $this->scope; |
539 | 601 | |
540 | - while ($scope !== null) { |
|
541 | - foreach ($this->state->inflectors as $class => $inflectors) { |
|
542 | - if ($instance instanceof $class) { |
|
543 | - foreach ($inflectors as $inflector) { |
|
602 | + while ($scope !== null) |
|
603 | + { |
|
604 | + foreach ($this->state->inflectors as $class => $inflectors) |
|
605 | + { |
|
606 | + if ($instance instanceof $class) |
|
607 | + { |
|
608 | + foreach ($inflectors as $inflector) |
|
609 | + { |
|
544 | 610 | $instance = $inflector->getParametersCount() > 1 |
545 | 611 | ? $this->invoker->invoke($inflector->inflector, [$instance]) |
546 | 612 | : ($inflector->inflector)($instance); |
@@ -556,9 +622,12 @@ discard block |
||
556 | 622 | |
557 | 623 | private function validateArguments(ContextFunction $reflection, array $arguments = []): bool |
558 | 624 | { |
559 | - try { |
|
625 | + try |
|
626 | + { |
|
560 | 627 | $this->resolver->validateArguments($reflection, $arguments); |
561 | - } catch (\Throwable) { |
|
628 | + } |
|
629 | + catch (\Throwable) |
|
630 | + { |
|
562 | 631 | return false; |
563 | 632 | } |
564 | 633 |