@@ -38,6 +38,8 @@ final class ConsoleProfilerListener implements EventSubscriberInterface
3838 /** @var \SplObjectStorage<Request, ?Request> */
3939 private \SplObjectStorage $ parents ;
4040
41+ private bool $ disabled = false ;
42+
4143 public function __construct (
4244 private readonly Profiler $ profiler ,
4345 private readonly RequestStack $ requestStack ,
@@ -66,7 +68,7 @@ public function initialize(ConsoleCommandEvent $event): void
6668
6769 $ input = $ event ->getInput ();
6870 if (!$ input ->hasOption ('profile ' ) || !$ input ->getOption ('profile ' )) {
69- $ this ->profiler -> disable () ;
71+ $ this ->disabled = true ;
7072
7173 return ;
7274 }
@@ -92,7 +94,12 @@ public function catch(ConsoleErrorEvent $event): void
9294
9395 public function profile (ConsoleTerminateEvent $ event ): void
9496 {
95- if (!$ this ->cliMode || !$ this ->profiler ->isEnabled ()) {
97+ $ error = $ this ->error ;
98+ $ this ->error = null ;
99+
100+ if (!$ this ->cliMode || $ this ->disabled ) {
101+ $ this ->disabled = false ;
102+
96103 return ;
97104 }
98105
@@ -114,8 +121,7 @@ public function profile(ConsoleTerminateEvent $event): void
114121 $ request ->command ->exitCode = $ event ->getExitCode ();
115122 $ request ->command ->interruptedBySignal = $ event ->getInterruptingSignal ();
116123
117- $ profile = $ this ->profiler ->collect ($ request , $ request ->getResponse (), $ this ->error );
118- $ this ->error = null ;
124+ $ profile = $ this ->profiler ->collect ($ request , $ request ->getResponse (), $ error );
119125 $ this ->profiles [$ request ] = $ profile ;
120126
121127 if ($ this ->parents [$ request ] = $ this ->requestStack ->getParentRequest ()) {
0 commit comments