@@ -31,7 +31,7 @@ public function __construct(
3131 parent ::__construct ($ kernel );
3232 $ this ->followRedirects ();
3333 $ this ->container = $ this ->getContainer ();
34- $ this ->rebootKernel (); // Ensure the profiler exists
34+ $ this ->rebootKernel ();
3535 }
3636
3737 /** @param Request $request */
@@ -47,7 +47,7 @@ protected function doRequest(object $request): Response
4747 }
4848
4949 /**
50- * Reboot kernel
50+ * Reboots the kernel.
5151 *
5252 * Services from the list of persistent services
5353 * are updated from service container before kernel shutdown
@@ -64,8 +64,7 @@ public function rebootKernel(): void
6464 }
6565
6666 $ this ->persistDoctrineConnections ();
67- $ this ->kernel ->boot ();
68- $ this ->kernel ->shutdown ();
67+ $ this ->ensureKernelShutdown ();
6968 $ this ->kernel ->boot ();
7069 $ this ->container = $ this ->getContainer ();
7170
@@ -82,6 +81,18 @@ public function rebootKernel(): void
8281 }
8382 }
8483
84+ protected function ensureKernelShutdown (): void
85+ {
86+ $ this ->kernel ->boot ();
87+ $ container = $ this ->kernel ->getContainer ();
88+
89+ if ($ container ->has ('services_resetter ' )) {
90+ $ container ->get ('services_resetter ' );
91+ }
92+
93+ $ this ->kernel ->shutdown ();
94+ }
95+
8596 private function getContainer (): ?ContainerInterface
8697 {
8798 /** @var ContainerInterface $container */
@@ -120,7 +131,9 @@ private function persistDoctrineConnections(): void
120131 }
121132
122133 $ reflectedContainer = new ReflectionClass ($ publicContainer );
123- $ reflectionTarget = $ reflectedContainer ->hasProperty ('parameters ' ) ? $ publicContainer : $ publicContainer ->getParameterBag ();
134+ $ reflectionTarget = $ reflectedContainer ->hasProperty ('parameters ' )
135+ ? $ publicContainer
136+ : $ publicContainer ->getParameterBag ();
124137
125138 $ reflectedParameters = new ReflectionProperty ($ reflectionTarget , 'parameters ' );
126139 $ reflectedParameters ->setAccessible (true );
0 commit comments