8000 Extract dispatching console signal handling and include subscribers · symfony/symfony@f8385fd · GitHub
[go: up one dir, main page]

Skip to content

Commit f8385fd

Browse files
Extract dispatching console signal handling and include subscribers
1 parent 0fc8f7a commit f8385fd

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -989,26 +989,13 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
989989
}
990990
}
991991

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);
1008993

1009994
foreach ($command->getSubscribedSignals() as $signal) {
1010995
$this->signalRegistry->register($signal, [$command, 'handleSignal']);
1011996
}
997+
} elseif ($this->dispatcher && $this->dispatcher->getListeners(ConsoleEvents::SIGNAL)) {
998+
$this->dispatchSignalEvents($command, $input, $output);
1012999
}
10131000

10141001
if (null === $this->dispatcher) {
@@ -1107,6 +1094,28 @@ protected function getDefaultHelperSet()
11071094
]);
11081095
}
11091096

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+
11101119
/**
11111120
* Returns abbreviated suggestions in string format.
11121121
*/

0 commit comments

Comments
 (0)
0