8000 bug #42091 [Console] Run commands when implements SignalableCommandIn… · shuvroroy/symfony@e737bd2 · GitHub
[go: up one dir, main page]

Skip to content

Commit e737bd2

Browse files
bug symfony#42091 [Console] Run commands when implements SignalableCommandInterface without pcntl and they have'nt signals (PaolaRuby)
This PR was squashed before being merged into the 5.2 branch. Discussion ---------- [Console] Run commands when implements SignalableCommandInterface without pcntl and they have'nt signals | Q | A | ------------- | --- | Branch? | 5.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix [symfony#42076](symfony#42076) | License | MIT When a command extends a class wich implements SignalableCommandInterface but the command has empty signals to dispatch, it still can be executed, It can be useful when the extension is not available and the command is necessary. Also, it can be used like a workaround for support other environments, for example windows servers, they don't have pcntl extension Commits ------- ad63d0b [Console] Run commands when implements SignalableCommandInterface without pcntl and they have'nt signals
2 parents 5514f15 + ad63d0b commit e737bd2

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
940940
}
941941
}
942942

943-
if ($command instanceof SignalableCommandInterface) {
943+
if ($command instanceof SignalableCommandInterface && ($this->signalsToDispatchEvent || $command->getSubscribedSignals())) {
944944
if (!$this->signalRegistry) {
945945
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.');
946946
}

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use Symfony\Component\Console\Output\Output;
3737
use Symfony\Component\Console\Output\OutputInterface;
3838
use Symfony\Component\Console\Output\StreamOutput;
39+
use Symfony\Component\Console\SignalRegistry\SignalRegistry;
3940
use Symfony\Component\Console\Tester\ApplicationTester;
4041
use Symfony\Component\DependencyInjection\ContainerBuilder;
4142
use Symfony\Component\EventDispatcher\EventDispatcher;
@@ -1861,6 +1862,18 @@ public function testSignal()
18611862
$this->assertTrue($command->signaled);
18621863
$this->assertTrue($dispatcherCalled);
18631864
}
1865+
1866+
public function testSignalableCommandInterfaceWithoutSignals()
1867+
{
1868+
$command = new SignableCommand();
1869+
1870+
$dispatcher = new EventDispatcher();
1871+
$application = new Application();
1872+
$application->setAutoExit(false);
1873+
$application->setDispatcher($dispatcher);
1874+
$application->add($command);
1875+
$this->assertSame(0, $application->run(new ArrayInput(['signal'])));
1876+
}
18641877
}
18651878

18661879
class CustomApplication extends Application
@@ -1928,7 +1941,7 @@ class SignableCommand extends Command implements SignalableCommandInterface
19281941

19291942
public function getSubscribedSignals(): array
19301943
{
1931-
return [\SIGALRM];
1944+
return SignalRegistry::isSupported() ? [\SIGALRM] : [];
19321945
}
19331946

19341947
public function handleSignal(int $signal): void

0 commit comments

Comments
 (0)
0