@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | { |
48 | 48 | $kernel = TestCore::create(['root' => __DIR__])->run(); |
49 | 49 | |
50 | - $d = new class() implements DispatcherInterface { |
|
50 | + $d = new class() implements DispatcherInterface{ |
|
51 | 51 | public static function canServe(EnvironmentInterface $env): bool |
52 | 52 | { |
53 | 53 | return true; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | { |
68 | 68 | $kernel = TestCore::create(['root' => __DIR__])->run(); |
69 | 69 | |
70 | - $d = new class() implements DispatcherInterface { |
|
70 | + $d = new class() implements DispatcherInterface{ |
|
71 | 71 | public function canServe(): bool |
72 | 72 | { |
73 | 73 | return true; |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | { |
91 | 91 | $kernel = TestCore::create(['root' => __DIR__])->run(); |
92 | 92 | |
93 | - $d = new class() implements DispatcherInterface { |
|
93 | + $d = new class() implements DispatcherInterface{ |
|
94 | 94 | public static function canServe(EnvironmentInterface $env): bool |
95 | 95 | { |
96 | 96 | return true; |
@@ -124,19 +124,19 @@ discard block |
||
124 | 124 | { |
125 | 125 | $kernel = TestCore::create(['root' => __DIR__]); |
126 | 126 | |
127 | - $kernel->booting(static function (TestCore $core) { |
|
127 | + $kernel->booting(static function (TestCore $core){ |
|
128 | 128 | $core->getContainer()->bind('abc', 'foo'); |
129 | 129 | }); |
130 | 130 | |
131 | - $kernel->booting(static function (TestCore $core) { |
|
131 | + $kernel->booting(static function (TestCore $core){ |
|
132 | 132 | $core->getContainer()->bind('bcd', 'foo'); |
133 | 133 | }); |
134 | 134 | |
135 | - $kernel->booted( static function (TestCore $core) { |
|
135 | + $kernel->booted(static function (TestCore $core){ |
|
136 | 136 | $core->getContainer()->bind('cde', 'foo'); |
137 | 137 | }); |
138 | 138 | |
139 | - $kernel->booted( static function (TestCore $core) { |
|
139 | + $kernel->booted(static function (TestCore $core){ |
|
140 | 140 | $core->getContainer()->bind('def', 'foo'); |
141 | 141 | }); |
142 | 142 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | |
160 | 160 | public function testEventsShouldBeDispatched(): void |
161 | 161 | { |
162 | - $testDispatcher = new class implements DispatcherInterface { |
|
162 | + $testDispatcher = new class implements DispatcherInterface{ |
|
163 | 163 | public static function canServe(EnvironmentInterface $env): bool |
164 | 164 | { |
165 | 165 | return true; |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | }; |
172 | 172 | |
173 | 173 | $container = new Container(); |
174 | - $kernel = TestCore::create(directories: ['root' => __DIR__,], container: $container) |
|
174 | + $kernel = TestCore::create(directories: ['root' => __DIR__, ], container: $container) |
|
175 | 175 | ->addDispatcher($testDispatcher); |
176 | 176 | |
177 | 177 | $dispatcher = $this->createMock(EventDispatcherInterface::class); |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | public function testDispatcherNotFoundEventShouldBeDispatched(): void |
193 | 193 | { |
194 | 194 | $container = new Container(); |
195 | - $kernel = TestCore::create(directories: ['root' => __DIR__,], container: $container); |
|
195 | + $kernel = TestCore::create(directories: ['root' => __DIR__, ], container: $container); |
|
196 | 196 | |
197 | 197 | $dispatcher = $this->createMock(EventDispatcherInterface::class); |
198 | 198 | $dispatcher |
@@ -47,7 +47,8 @@ discard block |
||
47 | 47 | { |
48 | 48 | $kernel = TestCore::create(['root' => __DIR__])->run(); |
49 | 49 | |
50 | - $d = new class() implements DispatcherInterface { |
|
50 | + $d = new class() implements DispatcherInterface |
|
51 | + { |
|
51 | 52 | public static function canServe(EnvironmentInterface $env): bool |
52 | 53 | { |
53 | 54 | return true; |
@@ -67,7 +68,8 @@ discard block |
||
67 | 68 | { |
68 | 69 | $kernel = TestCore::create(['root' => __DIR__])->run(); |
69 | 70 | |
70 | - $d = new class() implements DispatcherInterface { |
|
71 | + $d = new class() implements DispatcherInterface |
|
72 | + { |
|
71 | 73 | public function canServe(): bool |
72 | 74 | { |
73 | 75 | return true; |
@@ -90,7 +92,8 @@ discard block |
||
90 | 92 | { |
91 | 93 | $kernel = TestCore::create(['root' => __DIR__])->run(); |
92 | 94 | |
93 | - $d = new class() implements DispatcherInterface { |
|
95 | + $d = new class() implements DispatcherInterface |
|
96 | + { |
|
94 | 97 | public static function canServe(EnvironmentInterface $env): bool |
95 | 98 | { |
96 | 99 | return true; |
@@ -124,19 +127,23 @@ discard block |
||
124 | 127 | { |
125 | 128 | $kernel = TestCore::create(['root' => __DIR__]); |
126 | 129 | |
127 | - $kernel->booting(static function (TestCore $core) { |
|
130 | + $kernel->booting(static function (TestCore $core) |
|
131 | + { |
|
128 | 132 | $core->getContainer()->bind('abc', 'foo'); |
129 | 133 | }); |
130 | 134 | |
131 | - $kernel->booting(static function (TestCore $core) { |
|
135 | + $kernel->booting(static function (TestCore $core) |
|
136 | + { |
|
132 | 137 | $core->getContainer()->bind('bcd', 'foo'); |
133 | 138 | }); |
134 | 139 | |
135 | - $kernel->booted( static function (TestCore $core) { |
|
140 | + $kernel->booted( static function (TestCore $core) |
|
141 | + { |
|
136 | 142 | $core->getContainer()->bind('cde', 'foo'); |
137 | 143 | }); |
138 | 144 | |
139 | - $kernel->booted( static function (TestCore $core) { |
|
145 | + $kernel->booted( static function (TestCore $core) |
|
146 | + { |
|
140 | 147 | $core->getContainer()->bind('def', 'foo'); |
141 | 148 | }); |
142 | 149 | |
@@ -159,7 +166,8 @@ discard block |
||
159 | 166 | |
160 | 167 | public function testEventsShouldBeDispatched(): void |
161 | 168 | { |
162 | - $testDispatcher = new class implements DispatcherInterface { |
|
169 | + $testDispatcher = new class implements DispatcherInterface |
|
170 | + { |
|
163 | 171 | public static function canServe(EnvironmentInterface $env): bool |
164 | 172 | { |
165 | 173 | return true; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | protected readonly ExceptionHandlerInterface $exceptionHandler, |
78 | 78 | protected readonly BootloadManagerInterface $bootloader, |
79 | 79 | array $directories |
80 | - ) { |
|
80 | + ){ |
|
81 | 81 | $container->bindSingleton(ExceptionHandlerInterface::class, $exceptionHandler); |
82 | 82 | $container->bindSingleton(ExceptionRendererInterface::class, $exceptionHandler); |
83 | 83 | $container->bindSingleton(ExceptionReporterInterface::class, $exceptionHandler); |
@@ -114,35 +114,35 @@ discard block |
||
114 | 114 | final public static function create( |
115 | 115 | array $directories, |
116 | 116 | bool $handleErrors = true, |
117 | - ExceptionHandlerInterface|string|null $exceptionHandler = null, |
|
117 | + ExceptionHandlerInterface | string | null $exceptionHandler = null, |
|
118 | 118 | Container $container = new Container(), |
119 | - BootloadManagerInterface|Autowire|null $bootloadManager = null |
|
119 | + BootloadManagerInterface | Autowire | null $bootloadManager = null |
|
120 | 120 | ): static { |
121 | 121 | $exceptionHandler ??= ExceptionHandler::class; |
122 | 122 | |
123 | - if (\is_string($exceptionHandler)) { |
|
123 | + if (\is_string($exceptionHandler)){ |
|
124 | 124 | $exceptionHandler = $container->make($exceptionHandler); |
125 | 125 | } |
126 | 126 | |
127 | - if ($handleErrors) { |
|
127 | + if ($handleErrors){ |
|
128 | 128 | $exceptionHandler->register(); |
129 | 129 | } |
130 | 130 | |
131 | - if (!$container->has(InitializerInterface::class)) { |
|
131 | + if (!$container->has(InitializerInterface::class)){ |
|
132 | 132 | $container->bind(InitializerInterface::class, Initializer::class); |
133 | 133 | } |
134 | - if (!$container->has(InvokerStrategyInterface::class)) { |
|
134 | + if (!$container->has(InvokerStrategyInterface::class)){ |
|
135 | 135 | $container->bind(InvokerStrategyInterface::class, DefaultInvokerStrategy::class); |
136 | 136 | } |
137 | 137 | |
138 | - if ($bootloadManager instanceof Autowire) { |
|
138 | + if ($bootloadManager instanceof Autowire){ |
|
139 | 139 | $bootloadManager = $bootloadManager->resolve($container); |
140 | 140 | } |
141 | 141 | $bootloadManager ??= $container->make(StrategyBasedBootloadManager::class); |
142 | 142 | \assert($bootloadManager instanceof BootloadManagerInterface); |
143 | 143 | $container->bind(BootloadManagerInterface::class, $bootloadManager); |
144 | 144 | |
145 | - if (!$container->has(BootloaderRegistryInterface::class)) { |
|
145 | + if (!$container->has(BootloaderRegistryInterface::class)){ |
|
146 | 146 | $container->bindSingleton(BootloaderRegistryInterface::class, [self::class, 'initBootloaderRegistry']); |
147 | 147 | } |
148 | 148 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $environment ??= new Environment(); |
172 | 172 | $this->container->bindSingleton(EnvironmentInterface::class, $environment); |
173 | 173 | |
174 | - try { |
|
174 | + try{ |
|
175 | 175 | // will protect any against env overwrite action |
176 | 176 | $this->container->runScope( |
177 | 177 | [EnvironmentInterface::class => $environment], |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | $this->fireCallbacks($this->bootstrappedCallbacks); |
189 | 189 | } |
190 | 190 | ); |
191 | - } catch (\Throwable $e) { |
|
191 | + }catch (\Throwable $e){ |
|
192 | 192 | $this->exceptionHandler->handleGlobalException($e); |
193 | 193 | |
194 | 194 | return null; |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | public function running(Closure ...$callbacks): void |
211 | 211 | { |
212 | - foreach ($callbacks as $callback) { |
|
212 | + foreach ($callbacks as $callback){ |
|
213 | 213 | $this->runningCallbacks[] = $callback; |
214 | 214 | } |
215 | 215 | } |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | */ |
225 | 225 | public function booting(Closure ...$callbacks): void |
226 | 226 | { |
227 | - foreach ($callbacks as $callback) { |
|
227 | + foreach ($callbacks as $callback){ |
|
228 | 228 | $this->bootingCallbacks[] = $callback; |
229 | 229 | } |
230 | 230 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | */ |
240 | 240 | public function booted(Closure ...$callbacks): void |
241 | 241 | { |
242 | - foreach ($callbacks as $callback) { |
|
242 | + foreach ($callbacks as $callback){ |
|
243 | 243 | $this->bootedCallbacks[] = $callback; |
244 | 244 | } |
245 | 245 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | */ |
256 | 256 | public function bootstrapped(Closure ...$callbacks): void |
257 | 257 | { |
258 | - foreach ($callbacks as $callback) { |
|
258 | + foreach ($callbacks as $callback){ |
|
259 | 259 | $this->bootstrappedCallbacks[] = $callback; |
260 | 260 | } |
261 | 261 | } |
@@ -267,9 +267,9 @@ discard block |
||
267 | 267 | * @param class-string<DispatcherInterface>|DispatcherInterface $dispatcher The class name or instance |
268 | 268 | * of the dispatcher. Since v4.0, it will only accept the class name. |
269 | 269 | */ |
270 | - public function addDispatcher(string|DispatcherInterface $dispatcher): self |
|
270 | + public function addDispatcher(string | DispatcherInterface $dispatcher): self |
|
271 | 271 | { |
272 | - if (\is_object($dispatcher)) { |
|
272 | + if (\is_object($dispatcher)){ |
|
273 | 273 | $dispatcher = $dispatcher::class; |
274 | 274 | } |
275 | 275 | |
@@ -291,19 +291,19 @@ discard block |
||
291 | 291 | $eventDispatcher?->dispatch(new Serving()); |
292 | 292 | |
293 | 293 | $serving = $servingScope = null; |
294 | - foreach ($this->dispatchers as $dispatcher) { |
|
294 | + foreach ($this->dispatchers as $dispatcher){ |
|
295 | 295 | $reflection = new \ReflectionClass($dispatcher); |
296 | 296 | |
297 | 297 | $scope = ($reflection->getAttributes(DispatcherScope::class)[0] ?? null)?->newInstance()->scope; |
298 | 298 | $this->container->getBinder($scope)->bind($dispatcher, $dispatcher); |
299 | 299 | |
300 | - if ($serving === null && $this->canServe($reflection)) { |
|
300 | + if ($serving === null && $this->canServe($reflection)){ |
|
301 | 301 | $serving = $dispatcher; |
302 | 302 | $servingScope = $scope; |
303 | 303 | } |
304 | 304 | } |
305 | 305 | |
306 | - if ($serving === null) { |
|
306 | + if ($serving === null){ |
|
307 | 307 | $eventDispatcher?->dispatch(new DispatcherNotFound()); |
308 | 308 | throw new BootException('Unable to locate active dispatcher.'); |
309 | 309 | } |
@@ -352,13 +352,13 @@ discard block |
||
352 | 352 | */ |
353 | 353 | protected function fireCallbacks(array &$callbacks): void |
354 | 354 | { |
355 | - if ($callbacks === []) { |
|
355 | + if ($callbacks === []){ |
|
356 | 356 | return; |
357 | 357 | } |
358 | 358 | |
359 | - do { |
|
359 | + do{ |
|
360 | 360 | $this->container->invoke(\current($callbacks)); |
361 | - } while (\next($callbacks)); |
|
361 | + }while (\next($callbacks)); |
|
362 | 362 | |
363 | 363 | $callbacks = []; |
364 | 364 | } |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | */ |
399 | 399 | private function canServe(\ReflectionClass $reflection): bool |
400 | 400 | { |
401 | - if (!$reflection->hasMethod('canServe')) { |
|
401 | + if (!$reflection->hasMethod('canServe')){ |
|
402 | 402 | throw new BootException('Dispatcher must implement static `canServe` method.'); |
403 | 403 | } |
404 | 404 |
@@ -120,29 +120,35 @@ discard block |
||
120 | 120 | ): static { |
121 | 121 | $exceptionHandler ??= ExceptionHandler::class; |
122 | 122 | |
123 | - if (\is_string($exceptionHandler)) { |
|
123 | + if (\is_string($exceptionHandler)) |
|
124 | + { |
|
124 | 125 | $exceptionHandler = $container->make($exceptionHandler); |
125 | 126 | } |
126 | 127 | |
127 | - if ($handleErrors) { |
|
128 | + if ($handleErrors) |
|
129 | + { |
|
128 | 130 | $exceptionHandler->register(); |
129 | 131 | } |
130 | 132 | |
131 | - if (!$container->has(InitializerInterface::class)) { |
|
133 | + if (!$container->has(InitializerInterface::class)) |
|
134 | + { |
|
132 | 135 | $container->bind(InitializerInterface::class, Initializer::class); |
133 | 136 | } |
134 | - if (!$container->has(InvokerStrategyInterface::class)) { |
|
137 | + if (!$container->has(InvokerStrategyInterface::class)) |
|
138 | + { |
|
135 | 139 | $container->bind(InvokerStrategyInterface::class, DefaultInvokerStrategy::class); |
136 | 140 | } |
137 | 141 | |
138 | - if ($bootloadManager instanceof Autowire) { |
|
142 | + if ($bootloadManager instanceof Autowire) |
|
143 | + { |
|
139 | 144 | $bootloadManager = $bootloadManager->resolve($container); |
140 | 145 | } |
141 | 146 | $bootloadManager ??= $container->make(StrategyBasedBootloadManager::class); |
142 | 147 | \assert($bootloadManager instanceof BootloadManagerInterface); |
143 | 148 | $container->bind(BootloadManagerInterface::class, $bootloadManager); |
144 | 149 | |
145 | - if (!$container->has(BootloaderRegistryInterface::class)) { |
|
150 | + if (!$container->has(BootloaderRegistryInterface::class)) |
|
151 | + { |
|
146 | 152 | $container->bindSingleton(BootloaderRegistryInterface::class, [self::class, 'initBootloaderRegistry']); |
147 | 153 | } |
148 | 154 | |
@@ -171,7 +177,8 @@ discard block |
||
171 | 177 | $environment ??= new Environment(); |
172 | 178 | $this->container->bindSingleton(EnvironmentInterface::class, $environment); |
173 | 179 | |
174 | - try { |
|
180 | + try |
|
181 | + { |
|
175 | 182 | // will protect any against env overwrite action |
176 | 183 | $this->container->runScope( |
177 | 184 | [EnvironmentInterface::class => $environment], |
@@ -188,7 +195,9 @@ discard block |
||
188 | 195 | $this->fireCallbacks($this->bootstrappedCallbacks); |
189 | 196 | } |
190 | 197 | ); |
191 | - } catch (\Throwable $e) { |
|
198 | + } |
|
199 | + catch (\Throwable $e) |
|
200 | + { |
|
192 | 201 | $this->exceptionHandler->handleGlobalException($e); |
193 | 202 | |
194 | 203 | return null; |
@@ -209,7 +218,8 @@ discard block |
||
209 | 218 | */ |
210 | 219 | public function running(Closure ...$callbacks): void |
211 | 220 | { |
212 | - foreach ($callbacks as $callback) { |
|
221 | + foreach ($callbacks as $callback) |
|
222 | + { |
|
213 | 223 | $this->runningCallbacks[] = $callback; |
214 | 224 | } |
215 | 225 | } |
@@ -224,7 +234,8 @@ discard block |
||
224 | 234 | */ |
225 | 235 | public function booting(Closure ...$callbacks): void |
226 | 236 | { |
227 | - foreach ($callbacks as $callback) { |
|
237 | + foreach ($callbacks as $callback) |
|
238 | + { |
|
228 | 239 | $this->bootingCallbacks[] = $callback; |
229 | 240 | } |
230 | 241 | } |
@@ -239,7 +250,8 @@ discard block |
||
239 | 250 | */ |
240 | 251 | public function booted(Closure ...$callbacks): void |
241 | 252 | { |
242 | - foreach ($callbacks as $callback) { |
|
253 | + foreach ($callbacks as $callback) |
|
254 | + { |
|
243 | 255 | $this->bootedCallbacks[] = $callback; |
244 | 256 | } |
245 | 257 | } |
@@ -255,7 +267,8 @@ discard block |
||
255 | 267 | */ |
256 | 268 | public function bootstrapped(Closure ...$callbacks): void |
257 | 269 | { |
258 | - foreach ($callbacks as $callback) { |
|
270 | + foreach ($callbacks as $callback) |
|
271 | + { |
|
259 | 272 | $this->bootstrappedCallbacks[] = $callback; |
260 | 273 | } |
261 | 274 | } |
@@ -269,7 +282,8 @@ discard block |
||
269 | 282 | */ |
270 | 283 | public function addDispatcher(string|DispatcherInterface $dispatcher): self |
271 | 284 | { |
272 | - if (\is_object($dispatcher)) { |
|
285 | + if (\is_object($dispatcher)) |
|
286 | + { |
|
273 | 287 | $dispatcher = $dispatcher::class; |
274 | 288 | } |
275 | 289 | |
@@ -291,19 +305,22 @@ discard block |
||
291 | 305 | $eventDispatcher?->dispatch(new Serving()); |
292 | 306 | |
293 | 307 | $serving = $servingScope = null; |
294 | - foreach ($this->dispatchers as $dispatcher) { |
|
308 | + foreach ($this->dispatchers as $dispatcher) |
|
309 | + { |
|
295 | 310 | $reflection = new \ReflectionClass($dispatcher); |
296 | 311 | |
297 | 312 | $scope = ($reflection->getAttributes(DispatcherScope::class)[0] ?? null)?->newInstance()->scope; |
298 | 313 | $this->container->getBinder($scope)->bind($dispatcher, $dispatcher); |
299 | 314 | |
300 | - if ($serving === null && $this->canServe($reflection)) { |
|
315 | + if ($serving === null && $this->canServe($reflection)) |
|
316 | + { |
|
301 | 317 | $serving = $dispatcher; |
302 | 318 | $servingScope = $scope; |
303 | 319 | } |
304 | 320 | } |
305 | 321 | |
306 | - if ($serving === null) { |
|
322 | + if ($serving === null) |
|
323 | + { |
|
307 | 324 | $eventDispatcher?->dispatch(new DispatcherNotFound()); |
308 | 325 | throw new BootException('Unable to locate active dispatcher.'); |
309 | 326 | } |
@@ -352,11 +369,13 @@ discard block |
||
352 | 369 | */ |
353 | 370 | protected function fireCallbacks(array &$callbacks): void |
354 | 371 | { |
355 | - if ($callbacks === []) { |
|
372 | + if ($callbacks === []) |
|
373 | + { |
|
356 | 374 | return; |
357 | 375 | } |
358 | 376 | |
359 | - do { |
|
377 | + do |
|
378 | + { |
|
360 | 379 | $this->container->invoke(\current($callbacks)); |
361 | 380 | } while (\next($callbacks)); |
362 | 381 | |
@@ -398,7 +417,8 @@ discard block |
||
398 | 417 | */ |
399 | 418 | private function canServe(\ReflectionClass $reflection): bool |
400 | 419 | { |
401 | - if (!$reflection->hasMethod('canServe')) { |
|
420 | + if (!$reflection->hasMethod('canServe')) |
|
421 | + { |
|
402 | 422 | throw new BootException('Dispatcher must implement static `canServe` method.'); |
403 | 423 | } |
404 | 424 |
@@ -13,7 +13,7 @@ |
||
13 | 13 | final class ScopeTest extends TestCase |
14 | 14 | { |
15 | 15 | #[DataProvider('scopeNameDataProvider')] |
16 | - public function testScope(string|\BackedEnum $name, string $expected): void |
|
16 | + public function testScope(string | \BackedEnum $name, string $expected): void |
|
17 | 17 | { |
18 | 18 | $scope = new Scope($name); |
19 | 19 |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | $root = new Container(); |
35 | 35 | $root->bind('foo', SampleClass::class); |
36 | 36 | |
37 | - $root->runScoped(function (ContainerInterface $c1) { |
|
37 | + $root->runScoped(function (ContainerInterface $c1){ |
|
38 | 38 | $c1->get('foo'); |
39 | 39 | }, bindings: ['foo' => SampleClass::class]); |
40 | 40 | |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | |
322 | 322 | $root->runScope( |
323 | 323 | new Scope('foo'), |
324 | - function (ContainerInterface $c) { |
|
324 | + function (ContainerInterface $c){ |
|
325 | 325 | self::assertTrue($c->get('isFoo')); |
326 | 326 | $c->get('foo'); |
327 | 327 | } |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | $root = new Container(); |
335 | 335 | $root->getBinder($scope)->bindSingleton('foo', SampleClass::class); |
336 | 336 | |
337 | - $root->runScope(new Scope($scope), function (Container $container) { |
|
337 | + $root->runScope(new Scope($scope), function (Container $container){ |
|
338 | 338 | $this->assertTrue($container->has('foo')); |
339 | 339 | $this->assertInstanceOf(SampleClass::class, $container->get('foo')); |
340 | 340 | }); |
@@ -346,20 +346,20 @@ discard block |
||
346 | 346 | $root = new Container(); |
347 | 347 | $root->bindSingleton('sampleClass', SampleClass::class); |
348 | 348 | |
349 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
349 | + $root->runScope(new Scope('foo'), function (Container $container){ |
|
350 | 350 | $this->assertTrue($container->has('sampleClass')); |
351 | 351 | }); |
352 | 352 | |
353 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
354 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
353 | + $root->runScope(new Scope('foo'), function (Container $container){ |
|
354 | + $container->runScope(new Scope('bar'), function (Container $container){ |
|
355 | 355 | $this->assertTrue($container->has('sampleClass')); |
356 | 356 | }); |
357 | 357 | }); |
358 | 358 | |
359 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
359 | + $root->runScope(new Scope('foo'), function (Container $container){ |
|
360 | 360 | $container->bindSingleton('otherClass', SampleClass::class); |
361 | 361 | |
362 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
362 | + $container->runScope(new Scope('bar'), function (Container $container){ |
|
363 | 363 | $this->assertTrue($container->has('sampleClass')); |
364 | 364 | $this->assertTrue($container->has('otherClass')); |
365 | 365 | }); |
@@ -371,33 +371,33 @@ discard block |
||
371 | 371 | $root = new Container(); |
372 | 372 | $root->getBinder('foo')->bindSingleton('sampleClass', AttrScopeFoo::class); |
373 | 373 | |
374 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
374 | + $root->runScope(new Scope('foo'), function (Container $container){ |
|
375 | 375 | $this->assertTrue($container->has('sampleClass')); |
376 | 376 | }); |
377 | 377 | |
378 | - $root->runScope(new Scope('bar'), function (Container $container) { |
|
378 | + $root->runScope(new Scope('bar'), function (Container $container){ |
|
379 | 379 | $this->assertFalse($container->has('sampleClass')); |
380 | 380 | }); |
381 | 381 | |
382 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
383 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
382 | + $root->runScope(new Scope('foo'), function (Container $container){ |
|
383 | + $container->runScope(new Scope('bar'), function (Container $container){ |
|
384 | 384 | $this->assertTrue($container->has('sampleClass')); |
385 | 385 | }); |
386 | 386 | }); |
387 | 387 | |
388 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
388 | + $root->runScope(new Scope('foo'), function (Container $container){ |
|
389 | 389 | $container->bindSingleton('otherClass', AttrScopeFoo::class); |
390 | 390 | |
391 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
391 | + $container->runScope(new Scope('bar'), function (Container $container){ |
|
392 | 392 | $this->assertTrue($container->has('sampleClass')); |
393 | 393 | $this->assertTrue($container->has('otherClass')); |
394 | 394 | }); |
395 | 395 | }); |
396 | 396 | |
397 | - $root->runScope(new Scope('baz'), function (Container $container) { |
|
397 | + $root->runScope(new Scope('baz'), function (Container $container){ |
|
398 | 398 | $container->getBinder('foo')->bindSingleton('otherClass', AttrScopeFoo::class); |
399 | 399 | |
400 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
400 | + $container->runScope(new Scope('bar'), function (Container $container){ |
|
401 | 401 | $this->assertFalse($container->has('sampleClass')); |
402 | 402 | $this->assertFalse($container->has('otherClass')); |
403 | 403 | }); |
@@ -34,7 +34,8 @@ discard block |
||
34 | 34 | $root = new Container(); |
35 | 35 | $root->bind('foo', SampleClass::class); |
36 | 36 | |
37 | - $root->runScoped(function (ContainerInterface $c1) { |
|
37 | + $root->runScoped(function (ContainerInterface $c1) |
|
38 | + { |
|
38 | 39 | $c1->get('foo'); |
39 | 40 | }, bindings: ['foo' => SampleClass::class]); |
40 | 41 | |
@@ -67,7 +68,8 @@ discard block |
||
67 | 68 | { |
68 | 69 | $root = new Container(); |
69 | 70 | |
70 | - $root->runScoped(function (ContainerInterface $c1) use ($theSame, $alias) { |
|
71 | + $root->runScoped(function (ContainerInterface $c1) use ($theSame, $alias) |
|
72 | + { |
|
71 | 73 | $obj1 = $c1->get($alias); |
72 | 74 | $obj2 = $c1->get($alias); |
73 | 75 | |
@@ -92,14 +94,16 @@ discard block |
||
92 | 94 | { |
93 | 95 | $root = new Container(); |
94 | 96 | |
95 | - $root->runScoped(function (ContainerInterface $c1) use ($root) { |
|
97 | + $root->runScoped(function (ContainerInterface $c1) use ($root) |
|
98 | + { |
|
96 | 99 | $obj1 = $c1->get('foo'); |
97 | 100 | $this->weakMap->offsetSet($obj1, true); |
98 | 101 | |
99 | 102 | self::assertNotSame($root, $c1); |
100 | 103 | self::assertInstanceOf(stdClass::class, $obj1); |
101 | 104 | |
102 | - $c1->runScoped(function (ContainerInterface $c2) use ($root, $c1, $obj1) { |
|
105 | + $c1->runScoped(function (ContainerInterface $c2) use ($root, $c1, $obj1) |
|
106 | + { |
|
103 | 107 | $obj2 = $c2->get('foo'); |
104 | 108 | $this->weakMap->offsetSet($obj2, true); |
105 | 109 | |
@@ -128,14 +132,16 @@ discard block |
||
128 | 132 | $root->bindSingleton('bar', [Factory::class, 'makeStdClass']); |
129 | 133 | $root->bind(stdClass::class, new stdClass()); |
130 | 134 | |
131 | - $root->runScoped(function (ContainerInterface $c1) use ($root) { |
|
135 | + $root->runScoped(function (ContainerInterface $c1) use ($root) |
|
136 | + { |
|
132 | 137 | $obj1 = $c1->get('foo'); |
133 | 138 | $this->weakMap->offsetSet($obj1, true); |
134 | 139 | |
135 | 140 | self::assertInstanceOf(stdClass::class, $obj1); |
136 | 141 | // Singleton must be the same |
137 | 142 | self::assertSame($c1->get('bar'), $root->get('bar')); |
138 | - $c1->runScoped(function (ContainerInterface $c2) use ($root, $obj1) { |
|
143 | + $c1->runScoped(function (ContainerInterface $c2) use ($root, $obj1) |
|
144 | + { |
|
139 | 145 | $obj2 = $c2->get('foo'); |
140 | 146 | |
141 | 147 | self::assertInstanceOf(stdClass::class, $obj2); |
@@ -268,7 +274,8 @@ discard block |
||
268 | 274 | { |
269 | 275 | $root = new Container(); |
270 | 276 | |
271 | - $root->invoke(static function () use ($root) { |
|
277 | + $root->invoke(static function () use ($root) |
|
278 | + { |
|
272 | 279 | self::assertNotNull(\Spiral\Core\ContainerScope::getContainer()); |
273 | 280 | self::assertSame($root, \Spiral\Core\ContainerScope::getContainer()); |
274 | 281 | }); |
@@ -277,7 +284,8 @@ discard block |
||
277 | 284 | public function testRegisterContainerOnGet(): void |
278 | 285 | { |
279 | 286 | $root = new Container(); |
280 | - $root->bind('foo', function () use ($root) { |
|
287 | + $root->bind('foo', function () use ($root) |
|
288 | + { |
|
281 | 289 | self::assertNotNull(\Spiral\Core\ContainerScope::getContainer()); |
282 | 290 | self::assertSame($root, \Spiral\Core\ContainerScope::getContainer()); |
283 | 291 | }); |
@@ -288,7 +296,8 @@ discard block |
||
288 | 296 | public function testRegisterContainerOnMake(): void |
289 | 297 | { |
290 | 298 | $root = new Container(); |
291 | - $root->bind('foo', function () use ($root) { |
|
299 | + $root->bind('foo', function () use ($root) |
|
300 | + { |
|
292 | 301 | self::assertNotNull(\Spiral\Core\ContainerScope::getContainer()); |
293 | 302 | self::assertSame($root, \Spiral\Core\ContainerScope::getContainer()); |
294 | 303 | }); |
@@ -306,7 +315,8 @@ discard block |
||
306 | 315 | $root->bind('isFoo', new Scalar(false)); |
307 | 316 | $root->getBinder('foo')->bind('isFoo', new Scalar(true)); |
308 | 317 | |
309 | - $root->bind('foo', function (#[Proxy] ContainerInterface $c, ContainerInterface $r) use ($root) { |
|
318 | + $root->bind('foo', function (#[Proxy] ContainerInterface $c, ContainerInterface $r) use ($root) |
|
319 | + { |
|
310 | 320 | // Direct |
311 | 321 | self::assertNotNull(\Spiral\Core\ContainerScope::getContainer()); |
312 | 322 | self::assertNotSame($root, \Spiral\Core\ContainerScope::getContainer()); |
@@ -321,7 +331,8 @@ discard block |
||
321 | 331 | |
322 | 332 | $root->runScope( |
323 | 333 | new Scope('foo'), |
324 | - function (ContainerInterface $c) { |
|
334 | + function (ContainerInterface $c) |
|
335 | + { |
|
325 | 336 | self::assertTrue($c->get('isFoo')); |
326 | 337 | $c->get('foo'); |
327 | 338 | } |
@@ -334,7 +345,8 @@ discard block |
||
334 | 345 | $root = new Container(); |
335 | 346 | $root->getBinder($scope)->bindSingleton('foo', SampleClass::class); |
336 | 347 | |
337 | - $root->runScope(new Scope($scope), function (Container $container) { |
|
348 | + $root->runScope(new Scope($scope), function (Container $container) |
|
349 | + { |
|
338 | 350 | $this->assertTrue($container->has('foo')); |
339 | 351 | $this->assertInstanceOf(SampleClass::class, $container->get('foo')); |
340 | 352 | }); |
@@ -346,20 +358,25 @@ discard block |
||
346 | 358 | $root = new Container(); |
347 | 359 | $root->bindSingleton('sampleClass', SampleClass::class); |
348 | 360 | |
349 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
361 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
362 | + { |
|
350 | 363 | $this->assertTrue($container->has('sampleClass')); |
351 | 364 | }); |
352 | 365 | |
353 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
354 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
366 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
367 | + { |
|
368 | + $container->runScope(new Scope('bar'), function (Container $container) |
|
369 | + { |
|
355 | 370 | $this->assertTrue($container->has('sampleClass')); |
356 | 371 | }); |
357 | 372 | }); |
358 | 373 | |
359 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
374 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
375 | + { |
|
360 | 376 | $container->bindSingleton('otherClass', SampleClass::class); |
361 | 377 | |
362 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
378 | + $container->runScope(new Scope('bar'), function (Container $container) |
|
379 | + { |
|
363 | 380 | $this->assertTrue($container->has('sampleClass')); |
364 | 381 | $this->assertTrue($container->has('otherClass')); |
365 | 382 | }); |
@@ -371,33 +388,41 @@ discard block |
||
371 | 388 | $root = new Container(); |
372 | 389 | $root->getBinder('foo')->bindSingleton('sampleClass', AttrScopeFoo::class); |
373 | 390 | |
374 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
391 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
392 | + { |
|
375 | 393 | $this->assertTrue($container->has('sampleClass')); |
376 | 394 | }); |
377 | 395 | |
378 | - $root->runScope(new Scope('bar'), function (Container $container) { |
|
396 | + $root->runScope(new Scope('bar'), function (Container $container) |
|
397 | + { |
|
379 | 398 | $this->assertFalse($container->has('sampleClass')); |
380 | 399 | }); |
381 | 400 | |
382 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
383 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
401 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
402 | + { |
|
403 | + $container->runScope(new Scope('bar'), function (Container $container) |
|
404 | + { |
|
384 | 405 | $this->assertTrue($container->has('sampleClass')); |
385 | 406 | }); |
386 | 407 | }); |
387 | 408 | |
388 | - $root->runScope(new Scope('foo'), function (Container $container) { |
|
409 | + $root->runScope(new Scope('foo'), function (Container $container) |
|
410 | + { |
|
389 | 411 | $container->bindSingleton('otherClass', AttrScopeFoo::class); |
390 | 412 | |
391 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
413 | + $container->runScope(new Scope('bar'), function (Container $container) |
|
414 | + { |
|
392 | 415 | $this->assertTrue($container->has('sampleClass')); |
393 | 416 | $this->assertTrue($container->has('otherClass')); |
394 | 417 | }); |
395 | 418 | }); |
396 | 419 | |
397 | - $root->runScope(new Scope('baz'), function (Container $container) { |
|
420 | + $root->runScope(new Scope('baz'), function (Container $container) |
|
421 | + { |
|
398 | 422 | $container->getBinder('foo')->bindSingleton('otherClass', AttrScopeFoo::class); |
399 | 423 | |
400 | - $container->runScope(new Scope('bar'), function (Container $container) { |
|
424 | + $container->runScope(new Scope('bar'), function (Container $container) |
|
425 | + { |
|
401 | 426 | $this->assertFalse($container->has('sampleClass')); |
402 | 427 | $this->assertFalse($container->has('otherClass')); |
403 | 428 | }); |
@@ -14,8 +14,8 @@ |
||
14 | 14 | { |
15 | 15 | public readonly string $name; |
16 | 16 | |
17 | - public function __construct(string|\BackedEnum $name) |
|
17 | + public function __construct(string | \BackedEnum $name) |
|
18 | 18 | { |
19 | - $this->name = \is_object($name) ? (string) $name->value : $name; |
|
19 | + $this->name = \is_object($name) ? (string)$name->value : $name; |
|
20 | 20 | } |
21 | 21 | } |
@@ -20,9 +20,9 @@ |
||
20 | 20 | * as the first argument. Otherwise, {@see InvokerInterface::invoke()} will be used to invoke the closure. |
21 | 21 | */ |
22 | 22 | public function __construct( |
23 | - public readonly string|\BackedEnum|null $name = null, |
|
23 | + public readonly string | \BackedEnum | null $name = null, |
|
24 | 24 | public readonly array $bindings = [], |
25 | 25 | public readonly bool $autowire = true, |
26 | - ) { |
|
26 | + ){ |
|
27 | 27 | } |
28 | 28 | } |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | public const DEFAULT_ROOT_SCOPE_NAME = 'root'; |
48 | 48 | |
49 | 49 | private Internal\State $state; |
50 | - private ResolverInterface|Internal\Resolver $resolver; |
|
51 | - private FactoryInterface|Internal\Factory $factory; |
|
52 | - private ContainerInterface|Internal\Container $container; |
|
53 | - private BinderInterface|Internal\Binder $binder; |
|
54 | - private InvokerInterface|Internal\Invoker $invoker; |
|
50 | + private ResolverInterface | Internal\Resolver $resolver; |
|
51 | + private FactoryInterface | Internal\Factory $factory; |
|
52 | + private ContainerInterface | Internal\Container $container; |
|
53 | + private BinderInterface | Internal\Binder $binder; |
|
54 | + private InvokerInterface | Internal\Invoker $invoker; |
|
55 | 55 | private Internal\Scope $scope; |
56 | 56 | |
57 | 57 | /** |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function __construct( |
61 | 61 | private Config $config = new Config(), |
62 | - string|\BackedEnum|null $scopeName = self::DEFAULT_ROOT_SCOPE_NAME, |
|
62 | + string | \BackedEnum | null $scopeName = self::DEFAULT_ROOT_SCOPE_NAME, |
|
63 | 63 | private Options $options = new Options(), |
64 | - ) { |
|
65 | - if (\is_object($scopeName)) { |
|
66 | - $scopeName = (string) $scopeName->value; |
|
64 | + ){ |
|
65 | + if (\is_object($scopeName)){ |
|
66 | + $scopeName = (string)$scopeName->value; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | $this->initServices($this, $scopeName); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @throws \Throwable |
118 | 118 | * @psalm-suppress TooManyArguments |
119 | 119 | */ |
120 | - public function make(string $alias, array $parameters = [], \Stringable|string|null $context = null): mixed |
|
120 | + public function make(string $alias, array $parameters = [], \Stringable | string | null $context = null): mixed |
|
121 | 121 | { |
122 | 122 | return ContainerScope::getContainer() === $this |
123 | 123 | ? $this->factory->make($alias, $parameters, $context) |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @throws \Throwable |
144 | 144 | * @psalm-suppress TooManyArguments |
145 | 145 | */ |
146 | - public function get(string|Autowire $id, \Stringable|string|null $context = null): mixed |
|
146 | + public function get(string | Autowire $id, \Stringable | string | null $context = null): mixed |
|
147 | 147 | { |
148 | 148 | return ContainerScope::getContainer() === $this |
149 | 149 | ? $this->container->get($id, $context) |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | * If {@see string}, the default binder for the given scope will be returned. Default bindings won't affect |
164 | 164 | * already created Container instances except the case with the root one. |
165 | 165 | */ |
166 | - public function getBinder(string|\BackedEnum|null $scope = null): BinderInterface |
|
166 | + public function getBinder(string | \BackedEnum | null $scope = null): BinderInterface |
|
167 | 167 | { |
168 | - $scope = \is_object($scope) ? (string) $scope->value : $scope; |
|
168 | + $scope = \is_object($scope) ? (string)$scope->value : $scope; |
|
169 | 169 | |
170 | 170 | return $scope === null |
171 | 171 | ? $this->binder |
@@ -175,25 +175,25 @@ discard block |
||
175 | 175 | /** |
176 | 176 | * @throws \Throwable |
177 | 177 | */ |
178 | - public function runScope(Scope|array $bindings, callable $scope): mixed |
|
178 | + public function runScope(Scope | array $bindings, callable $scope): mixed |
|
179 | 179 | { |
180 | - if (!\is_array($bindings)) { |
|
180 | + if (!\is_array($bindings)){ |
|
181 | 181 | return $this->runIsolatedScope($bindings, $scope); |
182 | 182 | } |
183 | 183 | |
184 | 184 | $binds = &$this->state->bindings; |
185 | 185 | $singletons = &$this->state->singletons; |
186 | 186 | $cleanup = $previous = $prevSin = []; |
187 | - foreach ($bindings as $alias => $resolver) { |
|
187 | + foreach ($bindings as $alias => $resolver){ |
|
188 | 188 | // Store previous bindings |
189 | - if (isset($binds[$alias])) { |
|
189 | + if (isset($binds[$alias])){ |
|
190 | 190 | $previous[$alias] = $binds[$alias]; |
191 | - } else { |
|
191 | + }else{ |
|
192 | 192 | // Store bindings to be removed |
193 | 193 | $cleanup[] = $alias; |
194 | 194 | } |
195 | 195 | // Store previous singletons |
196 | - if (isset($singletons[$alias])) { |
|
196 | + if (isset($singletons[$alias])){ |
|
197 | 197 | $prevSin[$alias] = $singletons[$alias]; |
198 | 198 | unset($singletons[$alias]); |
199 | 199 | } |
@@ -201,21 +201,21 @@ discard block |
||
201 | 201 | $this->binder->bind($alias, $resolver); |
202 | 202 | } |
203 | 203 | |
204 | - try { |
|
204 | + try{ |
|
205 | 205 | return ContainerScope::getContainer() !== $this |
206 | 206 | ? ContainerScope::runScope($this, $scope) |
207 | 207 | : $scope($this); |
208 | - } finally { |
|
208 | + }finally{ |
|
209 | 209 | // Remove new bindings |
210 | - foreach ($cleanup as $alias) { |
|
210 | + foreach ($cleanup as $alias){ |
|
211 | 211 | unset($binds[$alias], $singletons[$alias]); |
212 | 212 | } |
213 | 213 | // Restore previous bindings |
214 | - foreach ($previous as $alias => $resolver) { |
|
214 | + foreach ($previous as $alias => $resolver){ |
|
215 | 215 | $binds[$alias] = $resolver; |
216 | 216 | } |
217 | 217 | // Restore singletons |
218 | - foreach ($prevSin as $alias => $instance) { |
|
218 | + foreach ($prevSin as $alias => $instance){ |
|
219 | 219 | $singletons[$alias] = $instance; |
220 | 220 | } |
221 | 221 | } |
@@ -261,9 +261,9 @@ discard block |
||
261 | 261 | * @param bool $force If the value is false, an exception will be thrown when attempting |
262 | 262 | * to bind an already constructed singleton. |
263 | 263 | */ |
264 | - public function bindSingleton(string $alias, string|array|callable|object $resolver, bool $force = true): void |
|
264 | + public function bindSingleton(string $alias, string | array | callable | object $resolver, bool $force = true): void |
|
265 | 265 | { |
266 | - if ($force) { |
|
266 | + if ($force){ |
|
267 | 267 | $this->binder->removeBinding($alias); |
268 | 268 | } |
269 | 269 | |
@@ -334,8 +334,8 @@ discard block |
||
334 | 334 | ], $this->options); |
335 | 335 | |
336 | 336 | // Create container services |
337 | - foreach ($container->config as $property => $class) { |
|
338 | - if (\property_exists($container, $property)) { |
|
337 | + foreach ($container->config as $property => $class){ |
|
338 | + if (\property_exists($container, $property)){ |
|
339 | 339 | $container->$property = $constructor->get($property, $class); |
340 | 340 | } |
341 | 341 | } |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | private function closeScope(): void |
350 | 350 | { |
351 | 351 | /** @psalm-suppress RedundantPropertyInitializationCheck */ |
352 | - if (!isset($this->scope)) { |
|
352 | + if (!isset($this->scope)){ |
|
353 | 353 | $this->destruct(); |
354 | 354 | return; |
355 | 355 | } |
@@ -358,10 +358,10 @@ discard block |
||
358 | 358 | |
359 | 359 | // Run finalizers |
360 | 360 | $errors = []; |
361 | - foreach ($this->state->finalizers as $finalizer) { |
|
362 | - try { |
|
361 | + foreach ($this->state->finalizers as $finalizer){ |
|
362 | + try{ |
|
363 | 363 | $this->invoker->invoke($finalizer); |
364 | - } catch (\Throwable $e) { |
|
364 | + }catch (\Throwable $e){ |
|
365 | 365 | $errors[] = $e; |
366 | 366 | } |
367 | 367 | } |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | $this->destruct(); |
371 | 371 | |
372 | 372 | // Throw collected errors |
373 | - if ($errors !== []) { |
|
373 | + if ($errors !== []){ |
|
374 | 374 | throw new FinalizersException($scopeName, $errors); |
375 | 375 | } |
376 | 376 | } |
@@ -392,18 +392,18 @@ discard block |
||
392 | 392 | $container->scope->setParent($this, $this->scope, $this->factory); |
393 | 393 | |
394 | 394 | // Add specific bindings |
395 | - foreach ($config->bindings as $alias => $resolver) { |
|
395 | + foreach ($config->bindings as $alias => $resolver){ |
|
396 | 396 | $container->binder->bind($alias, $resolver); |
397 | 397 | } |
398 | 398 | |
399 | 399 | return ContainerScope::runScope( |
400 | 400 | $container, |
401 | 401 | static function (self $container) use ($config, $closure): mixed { |
402 | - try { |
|
402 | + try{ |
|
403 | 403 | return $config->autowire |
404 | 404 | ? $container->invoke($closure) |
405 | 405 | : $closure($container); |
406 | - } finally { |
|
406 | + }finally{ |
|
407 | 407 | $container->closeScope(); |
408 | 408 | } |
409 | 409 | } |
@@ -62,7 +62,8 @@ discard block |
||
62 | 62 | string|\BackedEnum|null $scopeName = self::DEFAULT_ROOT_SCOPE_NAME, |
63 | 63 | private Options $options = new Options(), |
64 | 64 | ) { |
65 | - if (\is_object($scopeName)) { |
|
65 | + if (\is_object($scopeName)) |
|
66 | + { |
|
66 | 67 | $scopeName = (string) $scopeName->value; |
67 | 68 | } |
68 | 69 | |
@@ -177,23 +178,29 @@ discard block |
||
177 | 178 | */ |
178 | 179 | public function runScope(Scope|array $bindings, callable $scope): mixed |
179 | 180 | { |
180 | - if (!\is_array($bindings)) { |
|
181 | + if (!\is_array($bindings)) |
|
182 | + { |
|
181 | 183 | return $this->runIsolatedScope($bindings, $scope); |
182 | 184 | } |
183 | 185 | |
184 | 186 | $binds = &$this->state->bindings; |
185 | 187 | $singletons = &$this->state->singletons; |
186 | 188 | $cleanup = $previous = $prevSin = []; |
187 | - foreach ($bindings as $alias => $resolver) { |
|
189 | + foreach ($bindings as $alias => $resolver) |
|
190 | + { |
|
188 | 191 | // Store previous bindings |
189 | - if (isset($binds[$alias])) { |
|
192 | + if (isset($binds[$alias])) |
|
193 | + { |
|
190 | 194 | $previous[$alias] = $binds[$alias]; |
191 | - } else { |
|
195 | + } |
|
196 | + else |
|
197 | + { |
|
192 | 198 | // Store bindings to be removed |
193 | 199 | $cleanup[] = $alias; |
194 | 200 | } |
195 | 201 | // Store previous singletons |
196 | - if (isset($singletons[$alias])) { |
|
202 | + if (isset($singletons[$alias])) |
|
203 | + { |
|
197 | 204 | $prevSin[$alias] = $singletons[$alias]; |
198 | 205 | unset($singletons[$alias]); |
199 | 206 | } |
@@ -201,21 +208,27 @@ discard block |
||
201 | 208 | $this->binder->bind($alias, $resolver); |
202 | 209 | } |
203 | 210 | |
204 | - try { |
|
211 | + try |
|
212 | + { |
|
205 | 213 | return ContainerScope::getContainer() !== $this |
206 | 214 | ? ContainerScope::runScope($this, $scope) |
207 | 215 | : $scope($this); |
208 | - } finally { |
|
216 | + } |
|
217 | + finally |
|
218 | + { |
|
209 | 219 | // Remove new bindings |
210 | - foreach ($cleanup as $alias) { |
|
220 | + foreach ($cleanup as $alias) |
|
221 | + { |
|
211 | 222 | unset($binds[$alias], $singletons[$alias]); |
212 | 223 | } |
213 | 224 | // Restore previous bindings |
214 | - foreach ($previous as $alias => $resolver) { |
|
225 | + foreach ($previous as $alias => $resolver) |
|
226 | + { |
|
215 | 227 | $binds[$alias] = $resolver; |
216 | 228 | } |
217 | 229 | // Restore singletons |
218 | - foreach ($prevSin as $alias => $instance) { |
|
230 | + foreach ($prevSin as $alias => $instance) |
|
231 | + { |
|
219 | 232 | $singletons[$alias] = $instance; |
220 | 233 | } |
221 | 234 | } |
@@ -263,7 +276,8 @@ discard block |
||
263 | 276 | */ |
264 | 277 | public function bindSingleton(string $alias, string|array|callable|object $resolver, bool $force = true): void |
265 | 278 | { |
266 | - if ($force) { |
|
279 | + if ($force) |
|
280 | + { |
|
267 | 281 | $this->binder->removeBinding($alias); |
268 | 282 | } |
269 | 283 | |
@@ -334,8 +348,10 @@ discard block |
||
334 | 348 | ], $this->options); |
335 | 349 | |
336 | 350 | // Create container services |
337 | - foreach ($container->config as $property => $class) { |
|
338 | - if (\property_exists($container, $property)) { |
|
351 | + foreach ($container->config as $property => $class) |
|
352 | + { |
|
353 | + if (\property_exists($container, $property)) |
|
354 | + { |
|
339 | 355 | $container->$property = $constructor->get($property, $class); |
340 | 356 | } |
341 | 357 | } |
@@ -349,7 +365,8 @@ discard block |
||
349 | 365 | private function closeScope(): void |
350 | 366 | { |
351 | 367 | /** @psalm-suppress RedundantPropertyInitializationCheck */ |
352 | - if (!isset($this->scope)) { |
|
368 | + if (!isset($this->scope)) |
|
369 | + { |
|
353 | 370 | $this->destruct(); |
354 | 371 | return; |
355 | 372 | } |
@@ -358,10 +375,14 @@ discard block |
||
358 | 375 | |
359 | 376 | // Run finalizers |
360 | 377 | $errors = []; |
361 | - foreach ($this->state->finalizers as $finalizer) { |
|
362 | - try { |
|
378 | + foreach ($this->state->finalizers as $finalizer) |
|
379 | + { |
|
380 | + try |
|
381 | + { |
|
363 | 382 | $this->invoker->invoke($finalizer); |
364 | - } catch (\Throwable $e) { |
|
383 | + } |
|
384 | + catch (\Throwable $e) |
|
385 | + { |
|
365 | 386 | $errors[] = $e; |
366 | 387 | } |
367 | 388 | } |
@@ -370,7 +391,8 @@ discard block |
||
370 | 391 | $this->destruct(); |
371 | 392 | |
372 | 393 | // Throw collected errors |
373 | - if ($errors !== []) { |
|
394 | + if ($errors !== []) |
|
395 | + { |
|
374 | 396 | throw new FinalizersException($scopeName, $errors); |
375 | 397 | } |
376 | 398 | } |
@@ -392,18 +414,22 @@ discard block |
||
392 | 414 | $container->scope->setParent($this, $this->scope, $this->factory); |
393 | 415 | |
394 | 416 | // Add specific bindings |
395 | - foreach ($config->bindings as $alias => $resolver) { |
|
417 | + foreach ($config->bindings as $alias => $resolver) |
|
418 | + { |
|
396 | 419 | $container->binder->bind($alias, $resolver); |
397 | 420 | } |
398 | 421 | |
399 | 422 | return ContainerScope::runScope( |
400 | 423 | $container, |
401 | 424 | static function (self $container) use ($config, $closure): mixed { |
402 | - try { |
|
425 | + try |
|
426 | + { |
|
403 | 427 | return $config->autowire |
404 | 428 | ? $container->invoke($closure) |
405 | 429 | : $closure($container); |
406 | - } finally { |
|
430 | + } |
|
431 | + finally |
|
432 | + { |
|
407 | 433 | $container->closeScope(); |
408 | 434 | } |
409 | 435 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | final class DispatcherScope |
12 | 12 | { |
13 | 13 | public function __construct( |
14 | - public readonly string|\BackedEnum $scope |
|
15 | - ) { |
|
14 | + public readonly string | \BackedEnum $scope |
|
15 | + ){ |
|
16 | 16 | } |
17 | 17 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | private readonly FinalizerInterface $finalizer, |
30 | 30 | private readonly ContainerInterface $container, |
31 | 31 | private readonly ExceptionHandlerInterface $errorHandler, |
32 | - ) { |
|
32 | + ){ |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | public static function canServe(EnvironmentInterface $env): bool |
@@ -51,13 +51,13 @@ discard block |
||
51 | 51 | /** @var Console $console */ |
52 | 52 | $console = $this->container->get(Console::class); |
53 | 53 | |
54 | - try { |
|
54 | + try{ |
|
55 | 55 | return $console->start($input ?? new ArgvInput(), $output); |
56 | - } catch (Throwable $e) { |
|
56 | + }catch (Throwable $e){ |
|
57 | 57 | $this->handleException($e, $output); |
58 | 58 | |
59 | 59 | return 255; |
60 | - } finally { |
|
60 | + }finally{ |
|
61 | 61 | $listener->disable(); |
62 | 62 | $this->finalizer->finalize(false); |
63 | 63 | } |