[Console] Run commands when implements SignalableCommandInterface without pcntl and they have'nt signals

This commit is contained in:
PaoRuby 2021-07-13 10:09:00 -05:00 committed by Nicolas Grekas
parent 1f6a5a7cdc
commit ad63d0b553
2 changed files with 15 additions and 2 deletions

View File

@ -940,7 +940,7 @@ class Application implements ResetInterface
}
}
if ($command instanceof SignalableCommandInterface) {
if ($command instanceof SignalableCommandInterface && ($this->signalsToDispatchEvent || $command->getSubscribedSignals())) {
if (!$this->signalRegistry) {
throw new RuntimeException('Unable to subscribe to signal events. Make sure that the `pcntl` extension is installed and that "pcntl_*" functions are not disabled by your php.ini\'s "disable_functions" directive.');
}

View File

@ -36,6 +36,7 @@ use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Console\SignalRegistry\SignalRegistry;
use Symfony\Component\Console\Tester\ApplicationTester;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\EventDispatcher\EventDispatcher;
@ -1861,6 +1862,18 @@ class ApplicationTest extends TestCase
$this->assertTrue($command->signaled);
$this->assertTrue($dispatcherCalled);
}
public function testSignalableCommandInterfaceWithoutSignals()
{
$command = new SignableCommand();
$dispatcher = new EventDispatcher();
$application = new Application();
$application->setAutoExit(false);
$application->setDispatcher($dispatcher);
$application->add($command);
$this->assertSame(0, $application->run(new ArrayInput(['signal'])));
}
}
class CustomApplication extends Application
@ -1928,7 +1941,7 @@ class SignableCommand extends Command implements SignalableCommandInterface
public function getSubscribedSignals(): array
{
return [\SIGALRM];
return SignalRegistry::isSupported() ? [\SIGALRM] : [];
}
public function handleSignal(int $signal): void