44
55namespace Spiral \Boot ;
66
7- use Closure ;
87use Psr \EventDispatcher \EventDispatcherInterface ;
98use Spiral \Attribute \DispatcherScope ;
109use Spiral \Boot \Bootloader \BootloaderRegistry ;
@@ -57,16 +56,16 @@ abstract class AbstractKernel implements KernelInterface
5756 */
5857 protected array $ dispatchers = [];
5958
60- /** @var array<Closure> */
59+ /** @var array<\ Closure> */
6160 private array $ runningCallbacks = [];
6261
63- /** @var array<Closure> */
62+ /** @var array<\ Closure> */
6463 private array $ bootingCallbacks = [];
6564
66- /** @var array<Closure> */
65+ /** @var array<\ Closure> */
6766 private array $ bootedCallbacks = [];
6867
69- /** @var array<Closure> */
68+ /** @var array<\ Closure> */
7069 private array $ bootstrappedCallbacks = [];
7170
7271 /**
@@ -76,7 +75,7 @@ protected function __construct(
7675 protected readonly Container $ container ,
7776 protected readonly ExceptionHandlerInterface $ exceptionHandler ,
7877 protected readonly BootloadManagerInterface $ bootloader ,
79- array $ directories
78+ array $ directories,
8079 ) {
8180 $ container ->bindSingleton (ExceptionHandlerInterface::class, $ exceptionHandler );
8281 $ container ->bindSingleton (ExceptionRendererInterface::class, $ exceptionHandler );
@@ -89,21 +88,13 @@ protected function __construct(
8988
9089 $ container ->bindSingleton (
9190 DirectoriesInterface::class,
92- new Directories ($ this ->mapDirectories ($ directories ))
91+ new Directories ($ this ->mapDirectories ($ directories )),
9392 );
9493
9594 $ this ->finalizer = new Finalizer ();
9695 $ container ->bindSingleton (FinalizerInterface::class, $ this ->finalizer );
9796 }
9897
99- /**
100- * Terminate the application.
101- */
102- public function __destruct ()
103- {
104- $ this ->finalizer ->finalize (true );
105- }
106-
10798 /**
10899 * Create an application instance.
109100 *
@@ -116,7 +107,7 @@ final public static function create(
116107 bool $ handleErrors = true ,
117108 ExceptionHandlerInterface |string |null $ exceptionHandler = null ,
118109 Container $ container = new Container (),
119- BootloadManagerInterface |Autowire |null $ bootloadManager = null
110+ BootloadManagerInterface |Autowire |null $ bootloadManager = null ,
120111 ): static {
121112 $ exceptionHandler ??= ExceptionHandler::class;
122113
@@ -151,21 +142,20 @@ final public static function create(
151142 $ container ,
152143 $ exceptionHandler ,
153144 $ bootloadManager ,
154- $ directories
145+ $ directories,
155146 );
156147 }
157148
158149 /**
159150 * Run the application with given Environment
160151 *
161- * $app = App::create([...]);
162- * $app->booting(...);
163- * $app->booted(...);
164- * $app->bootstrapped(...);
165- * $app->run(new Environment([
166- * 'APP_ENV' => 'production'
167- * ]));
168- *
152+ * $app = App::create([...]);
153+ * $app->booting(...);
154+ * $app->booted(...);
155+ * $app->bootstrapped(...);
156+ * $app->run(new Environment([
157+ * 'APP_ENV' => 'production'
158+ * ]));
169159 */
170160 public function run (?EnvironmentInterface $ environment = null ): ?self
171161 {
@@ -187,7 +177,7 @@ function (Container $container): void {
187177 $ this ->bootstrap ();
188178
189179 $ this ->fireCallbacks ($ this ->bootstrappedCallbacks );
190- }
180+ },
191181 );
192182 } catch (\Throwable $ e ) {
193183 $ this ->exceptionHandler ->handleGlobalException ($ e );
@@ -208,7 +198,7 @@ function (Container $container): void {
208198 * $kernel->getContainer()->...
209199 * });
210200 */
211- public function running (Closure ...$ callbacks ): void
201+ public function running (\ Closure ...$ callbacks ): void
212202 {
213203 foreach ($ callbacks as $ callback ) {
214204 $ this ->runningCallbacks [] = $ callback ;
@@ -223,7 +213,7 @@ public function running(Closure ...$callbacks): void
223213 * $kernel->getContainer()->...
224214 * });
225215 */
226- public function booting (Closure ...$ callbacks ): void
216+ public function booting (\ Closure ...$ callbacks ): void
227217 {
228218 foreach ($ callbacks as $ callback ) {
229219 $ this ->bootingCallbacks [] = $ callback ;
@@ -238,14 +228,13 @@ public function booting(Closure ...$callbacks): void
238228 * $kernel->getContainer()->...
239229 * });
240230 */
241- public function booted (Closure ...$ callbacks ): void
231+ public function booted (\ Closure ...$ callbacks ): void
242232 {
243233 foreach ($ callbacks as $ callback ) {
244234 $ this ->bootedCallbacks [] = $ callback ;
245235 }
246236 }
247237
248-
249238 /**
250239 * Register a new callback, that will be fired after framework bootstrapped.
251240 * (Before serving)
@@ -254,7 +243,7 @@ public function booted(Closure ...$callbacks): void
254243 * $kernel->getContainer()->...
255244 * });
256245 */
257- public function bootstrapped (Closure ...$ callbacks ): void
246+ public function bootstrapped (\ Closure ...$ callbacks ): void
258247 {
259248 foreach ($ callbacks as $ callback ) {
260249 $ this ->bootstrappedCallbacks [] = $ callback ;
@@ -314,10 +303,18 @@ public function serve(): mixed
314303 static function (DispatcherInterface $ dispatcher ) use ($ eventDispatcher ): mixed {
315304 $ eventDispatcher ?->dispatch(new DispatcherFound ($ dispatcher ));
316305 return $ dispatcher ->serve ();
317- }
306+ },
318307 );
319308 }
320309
310+ /**
311+ * Terminate the application.
312+ */
313+ public function __destruct ()
314+ {
315+ $ this ->finalizer ->finalize (true );
316+ }
317+
321318 /**
322319 * Bootstrap application. Must be executed before serve method.
323320 */
@@ -376,7 +373,7 @@ private function bootload(array $bootloaders = []): void
376373 static function () use ($ self ): void {
377374 $ self ->fireCallbacks ($ self ->bootingCallbacks );
378375 },
379- ]
376+ ],
380377 );
381378
382379 $ this ->fireCallbacks ($ this ->bootedCallbacks );
0 commit comments