@@ -35,9 +35,10 @@ final class FrameworkKernel implements Kernel
3535 public function __construct (
3636 public string $ root ,
3737 /** @var DiscoveryLocation[] */
38- private array $ discoveryLocations = [],
38+ private readonly array $ discoveryLocations = [],
3939 ?Container $ container = null ,
4040 ?string $ internalStorage = null ,
41+ private readonly bool $ longRunning = false ,
4142 ) {
4243 $ this ->container = $ container ?? $ this ->createContainer ();
4344
@@ -51,6 +52,7 @@ public static function boot(
5152 array $ discoveryLocations = [],
5253 ?Container $ container = null ,
5354 ?string $ internalStorage = null ,
55+ bool $ longRunning = false ,
5456 ): self {
5557 if (! defined ('TEMPEST_START ' )) {
5658 define ('TEMPEST_START ' , value: hrtime (as_number: true ));
@@ -61,6 +63,7 @@ public static function boot(
6163 discoveryLocations: $ discoveryLocations ,
6264 container: $ container ,
6365 internalStorage: $ internalStorage ,
66+ longRunning: $ longRunning ,
6467 )
6568 ->registerKernel ()
6669 ->validateRoot ()
@@ -98,12 +101,23 @@ public function validateRoot(): self
98101 return $ this ;
99102 }
100103
101- public function shutdown (int |string $ status = '' ): never
104+ public function shutdown (int |string $ status = '' ): void
102105 {
103- $ this ->finishDeferredTasks ()
104- ->event (KernelEvent::SHUTDOWN );
106+ $ this ->event (KernelEvent::SHUTTING_DOWN )
107+ ->finishDeferredTasks ();
108+
109+ if ($ this ->longRunning ) {
110+ $ this
111+ ->event (KernelEvent::RESETTING )
112+ ->resetContainer ()
113+ ->event (KernelEvent::RESET );
114+ }
115+
116+ $ this ->event (KernelEvent::SHUTDOWN );
105117
106- exit ($ status );
118+ if (! $ this ->longRunning ) {
119+ exit ($ status );
120+ }
107121 }
108122
109123 public function loadComposer (): self
@@ -236,6 +250,13 @@ public function finishDeferredTasks(): self
236250 return $ this ;
237251 }
238252
253+ public function resetContainer (): self
254+ {
255+ $ this ->container ->reset ();
256+
257+ return $ this ;
258+ }
259+
239260 public function event (object $ event ): self
240261 {
241262 if (interface_exists (EventBus::class)) {
0 commit comments