@@ -38,6 +38,8 @@ final class ConsoleProfilerListener implements EventSubscriberInterface
38
38
/** @var \SplObjectStorage<Request, ?Request> */
39
39
private \SplObjectStorage $ parents ;
40
40
41
+ private bool $ disabled = false ;
42
+
41
43
public function __construct (
42
44
private readonly Profiler $ profiler ,
43
45
private readonly RequestStack $ requestStack ,
@@ -66,7 +68,7 @@ public function initialize(ConsoleCommandEvent $event): void
66
68
67
69
$ input = $ event ->getInput ();
68
70
if (!$ input ->hasOption ('profile ' ) || !$ input ->getOption ('profile ' )) {
69
- $ this ->profiler -> disable () ;
71
+ $ this ->disabled = true ;
70
72
71
73
return ;
72
74
}
@@ -92,7 +94,12 @@ public function catch(ConsoleErrorEvent $event): void
92
94
93
95
public function profile (ConsoleTerminateEvent $ event ): void
94
96
{
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
+
96
103
return ;
97
104
}
98
105
@@ -114,8 +121,7 @@ public function profile(ConsoleTerminateEvent $event): void
114
121
$ request ->command ->exitCode = $ event ->getExitCode ();
115
122
$ request ->command ->interruptedBySignal = $ event ->getInterruptingSignal ();
116
123
117
- $ profile = $ this ->profiler ->collect ($ request , $ request ->getResponse (), $ this ->error );
118
- $ this ->error = null ;
124
+ $ profile = $ this ->profiler ->collect ($ request , $ request ->getResponse (), $ error );
119
125
$ this ->profiles [$ request ] = $ profile ;
120
126
121
127
if ($ this ->parents [$ request ] = $ this ->requestStack ->getParentRequest ()) {