@@ -989,26 +989,13 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
989
989
}
990
990
}
991
991
992
- if ($ this ->dispatcher ) {
993
- foreach ($ this ->signalsToDispatchEvent as $ signal ) {
994
- $ event = new ConsoleSignalEvent ($ command , $ input , $ output , $ signal );
995
-
996
- $ this ->signalRegistry ->register ($ signal , function ($ signal , $ hasNext ) use ($ event ) {
997
- $ this ->dispatcher ->dispatch ($ event , ConsoleEvents::SIGNAL );
998
-
999
- // No more handlers, we try to simulate PHP default behavior
1000
- if (!$ hasNext ) {
1001
- if (!\in_array ($ signal , [\SIGUSR1 , \SIGUSR2 ], true )) {
1002
- exit (0 );
1003
- }
1004
- }
1005
- });
1006
- }
1007
- }
992
+ $ this ->dispatchSignalEvents ($ command , $ input , $ output );
1008
993
1009
994
foreach ($ command ->getSubscribedSignals () as $ signal ) {
1010
995
$ this ->signalRegistry ->register ($ signal , [$ command , 'handleSignal ' ]);
1011
996
}
997
+ } elseif ($ this ->dispatcher && $ this ->dispatcher ->getListeners (ConsoleEvents::SIGNAL )) {
998
+ $ this ->dispatchSignalEvents ($ command , $ input , $ output );
1012
999
}
1013
1000
1014
1001
if (null === $ this ->dispatcher ) {
@@ -1107,6 +1094,28 @@ protected function getDefaultHelperSet()
1107
1094
]);
1108
1095
}
1109
1096
1097
+ private function dispatchSignalEvents (Command $ command , InputInterface $ input , OutputInterface $ output )
1098
+ {
1099
+ if (!$ this ->dispatcher ) {
1100
+ return ;
1101
+ }
1102
+
1103
+ foreach ($ this ->signalsToDispatchEvent as $ signal ) {
1104
+ $ event = new ConsoleSignalEvent ($ command , $ input , $ output , $ signal );
1105
+
1106
+ $ this ->signalRegistry ->register ($ signal , function ($ signal , $ hasNext ) use ($ event ) {
1107
+ $ this ->dispatcher ->dispatch ($ event , ConsoleEvents::SIGNAL );
1108
+
1109
+ // No more handlers, we try to simulate PHP default behavior
1110
+ if (!$ hasNext ) {
1111
+ if (!\in_array ($ signal , [\SIGUSR1 , \SIGUSR2 ], true )) {
1112
+ exit (0 );
1113
+ }
1114
+ }
1115
+ });
1116
+ }
1117
+ }
1118
+
1110
1119
/**
1111
1120
* Returns abbreviated suggestions in string format.
1112
1121
*/
0 commit comments