File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed
Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 11name : Tasks
22
3- on : push
3+ on :
4+ push :
5+ pull_request :
46
57jobs :
68 lint-php :
Original file line number Diff line number Diff line change 44
55namespace Kanti \ServerTiming \EventListener ;
66
7+ use Exception ;
78use Kanti \ServerTiming \Dto \ScriptResult ;
8- use Kanti \ServerTiming \SqlLogging \SqlLoggerCore11 ;
99use Kanti \ServerTiming \Utility \TimingUtility ;
1010use Symfony \Component \Console \Event \ConsoleCommandEvent ;
1111use Symfony \Component \Console \Event \ConsoleTerminateEvent ;
12+ use Kanti \ServerTiming \Dto \StopWatch ;
1213
1314final class ConsoleCommandEventListener
1415{
16+ /** @var StopWatch[] */
17+ private array $ stopWatches = [];
18+
1519 public function start (ConsoleCommandEvent $ event ): void
1620 {
17- TimingUtility::start ('console.command ' , (string )$ event ->getCommand ()?->getName());
21+ $ this -> stopWatches [] = TimingUtility::stopWatch ('console.command ' , (string )$ event ->getCommand ()?->getName());
1822 }
1923
2024 public function stop (ConsoleTerminateEvent $ event ): void
2125 {
22- TimingUtility::end ('console.command ' );
23- TimingUtility::getInstance ()->shutdown (ScriptResult::fromCli ($ event ->getExitCode ()));
26+ $ stopWatch = array_pop ($ this ->stopWatches );
27+ if ($ stopWatch === null ) {
28+ throw new Exception ('No stopWatch found, did you start the command already? ' );
29+ }
30+
31+ $ stopWatch ->stop ();
32+ if (!$ this ->stopWatches ) {
33+ TimingUtility::getInstance ()->shutdown (ScriptResult::fromCli ($ event ->getExitCode ()));
34+ }
2435 }
2536}
You can’t perform that action at this time.
0 commit comments