Skip to content

Commit ed30487

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [Translation][Lokalize] Configure `replace_breaks` to prevent issues with multilines translations Improve message when shell is not detected ensure docblock compatibility with PhpStan's docblock parser Fix signal handlers called after event listeners and skip exit
2 parents 65427ec + dcda527 commit ed30487

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

Application.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -986,10 +986,6 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
986986
});
987987
}
988988
}
989-
990-
foreach ($commandSignals as $signal) {
991-
$this->signalRegistry->register($signal, [$command, 'handleSignal']);
992-
}
993989
}
994990

995991
if (null !== $this->dispatcher) {
@@ -1008,6 +1004,10 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
10081004
});
10091005
}
10101006
}
1007+
1008+
foreach ($commandSignals as $signal) {
1009+
$this->signalRegistry->register($signal, [$command, 'handleSignal']);
1010+
}
10111011
}
10121012

10131013
if (null === $this->dispatcher) {

Command/DumpCompletionCommand.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9393
if (!file_exists($completionFile)) {
9494
$supportedShells = $this->getSupportedShells();
9595

96-
($output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output)
97-
->writeln(sprintf('<error>Detected shell "%s", which is not supported by Symfony shell completion (supported shells: "%s").</>', $shell, implode('", "', $supportedShells)));
96+
if ($output instanceof ConsoleOutputInterface) {
97+
$output = $output->getErrorOutput();
98+
}
99+
if ($shell) {
100+
$output->writeln(sprintf('<error>Detected shell "%s", which is not supported by Symfony shell completion (supported shells: "%s").</>', $shell, implode('", "', $supportedShells)));
101+
} else {
102+
$output->writeln(sprintf('<error>Shell not detected, Symfony shell completion only supports "%s").</>', implode('", "', $supportedShells)));
103+
}
98104

99105
return self::INVALID;
100106
}

Tests/ApplicationTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,21 @@ public function testSignalableCommandInterfaceWithoutSignals()
19751975
$this->assertSame(0, $application->run(new ArrayInput(['signal'])));
19761976
}
19771977

1978+
public function testSignalableCommandHandlerCalledAfterEventListener()
1979+
{
1980+
$command = new SignableCommand();
1981+
1982+
$subscriber = new SignalEventSubscriber();
1983+
1984+
$dispatcher = new EventDispatcher();
1985+
$dispatcher->addSubscriber($subscriber);
1986+
1987+
$application = $this->createSignalableApplication($command, $dispatcher);
1988+
$application->setSignalsToDispatchEvent(\SIGUSR1);
1989+
$this->assertSame(1, $application->run(new ArrayInput(['signal'])));
1990+
$this->assertSame([SignalEventSubscriber::class, SignableCommand::class], $command->signalHandlers);
1991+
}
1992+
19781993
/**
19791994
* @group tty
19801995
*/
@@ -2073,6 +2088,7 @@ public function isEnabled(): bool
20732088
class BaseSignableCommand extends Command
20742089
{
20752090
public $signaled = false;
2091+
public $signalHandlers = [];
20762092
public $loop = 1000;
20772093
private $emitsSignal;
20782094

@@ -2113,6 +2129,7 @@ public function getSubscribedSignals(): array
21132129
public function handleSignal(int $signal): void
21142130
{
21152131
$this->signaled = true;
2132+
$this->signalHandlers[] = __CLASS__;
21162133
}
21172134
}
21182135

@@ -2124,6 +2141,7 @@ public function onSignal(ConsoleSignalEvent $event): void
21242141
{
21252142
$this->signaled = true;
21262143
$event->getCommand()->signaled = true;
2144+
$event->getCommand()->signalHandlers[] = __CLASS__;
21272145
}
21282146

21292147
public static function getSubscribedEvents(): array

0 commit comments

Comments
 (0)