mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
N°6934 - Symfony 6.4 - upgrade Symfony bundles to 6.4 (#580)
* Update Symfony lib to version ~6.4.0 * Update code missing return type * Add an iTop general configuration entry to store application secret (Symfony mandatory parameter) * Use dependency injection in ExceptionListener & UserProvider classes
This commit is contained in:
@@ -21,6 +21,7 @@ use Symfony\Component\Console\Command\SignalableCommandInterface;
|
||||
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
|
||||
use Symfony\Component\Console\Completion\CompletionInput;
|
||||
use Symfony\Component\Console\Completion\CompletionSuggestions;
|
||||
use Symfony\Component\Console\Completion\Suggestion;
|
||||
use Symfony\Component\Console\Event\ConsoleCommandEvent;
|
||||
use Symfony\Component\Console\Event\ConsoleErrorEvent;
|
||||
use Symfony\Component\Console\Event\ConsoleSignalEvent;
|
||||
@@ -32,6 +33,7 @@ use Symfony\Component\Console\Exception\NamespaceNotFoundException;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||
use Symfony\Component\Console\Helper\DebugFormatterHelper;
|
||||
use Symfony\Component\Console\Helper\DescriptorHelper;
|
||||
use Symfony\Component\Console\Helper\FormatterHelper;
|
||||
use Symfony\Component\Console\Helper\Helper;
|
||||
use Symfony\Component\Console\Helper\HelperSet;
|
||||
@@ -70,23 +72,24 @@ use Symfony\Contracts\Service\ResetInterface;
|
||||
*/
|
||||
class Application implements ResetInterface
|
||||
{
|
||||
private $commands = [];
|
||||
private $wantHelps = false;
|
||||
private $runningCommand;
|
||||
private $name;
|
||||
private $version;
|
||||
private $commandLoader;
|
||||
private $catchExceptions = true;
|
||||
private $autoExit = true;
|
||||
private $definition;
|
||||
private $helperSet;
|
||||
private $dispatcher;
|
||||
private $terminal;
|
||||
private $defaultCommand;
|
||||
private $singleCommand = false;
|
||||
private $initialized;
|
||||
private $signalRegistry;
|
||||
private $signalsToDispatchEvent = [];
|
||||
private array $commands = [];
|
||||
private bool $wantHelps = false;
|
||||
private ?Command $runningCommand = null;
|
||||
private string $name;
|
||||
private string $version;
|
||||
private ?CommandLoaderInterface $commandLoader = null;
|
||||
private bool $catchExceptions = true;
|
||||
private bool $catchErrors = false;
|
||||
private bool $autoExit = true;
|
||||
private InputDefinition $definition;
|
||||
private HelperSet $helperSet;
|
||||
private ?EventDispatcherInterface $dispatcher = null;
|
||||
private Terminal $terminal;
|
||||
private string $defaultCommand;
|
||||
private bool $singleCommand = false;
|
||||
private bool $initialized = false;
|
||||
private ?SignalRegistry $signalRegistry = null;
|
||||
private array $signalsToDispatchEvent = [];
|
||||
|
||||
public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN')
|
||||
{
|
||||
@@ -103,11 +106,14 @@ class Application implements ResetInterface
|
||||
/**
|
||||
* @final
|
||||
*/
|
||||
public function setDispatcher(EventDispatcherInterface $dispatcher)
|
||||
public function setDispatcher(EventDispatcherInterface $dispatcher): void
|
||||
{
|
||||
$this->dispatcher = $dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setCommandLoader(CommandLoaderInterface $commandLoader)
|
||||
{
|
||||
$this->commandLoader = $commandLoader;
|
||||
@@ -116,12 +122,15 @@ class Application implements ResetInterface
|
||||
public function getSignalRegistry(): SignalRegistry
|
||||
{
|
||||
if (!$this->signalRegistry) {
|
||||
throw new RuntimeException('Signals are not supported. Make sure that the `pcntl` extension is installed and that "pcntl_*" functions are not disabled by your php.ini\'s "disable_functions" directive.');
|
||||
throw new RuntimeException('Signals are not supported. Make sure that the "pcntl" extension is installed and that "pcntl_*" functions are not disabled by your php.ini\'s "disable_functions" directive.');
|
||||
}
|
||||
|
||||
return $this->signalRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setSignalsToDispatchEvent(int ...$signalsToDispatchEvent)
|
||||
{
|
||||
$this->signalsToDispatchEvent = $signalsToDispatchEvent;
|
||||
@@ -134,20 +143,15 @@ class Application implements ResetInterface
|
||||
*
|
||||
* @throws \Exception When running fails. Bypass this when {@link setCatchExceptions()}.
|
||||
*/
|
||||
public function run(InputInterface $input = null, OutputInterface $output = null)
|
||||
public function run(InputInterface $input = null, OutputInterface $output = null): int
|
||||
{
|
||||
if (\function_exists('putenv')) {
|
||||
@putenv('LINES='.$this->terminal->getHeight());
|
||||
@putenv('COLUMNS='.$this->terminal->getWidth());
|
||||
}
|
||||
|
||||
if (null === $input) {
|
||||
$input = new ArgvInput();
|
||||
}
|
||||
|
||||
if (null === $output) {
|
||||
$output = new ConsoleOutput();
|
||||
}
|
||||
$input ??= new ArgvInput();
|
||||
$output ??= new ConsoleOutput();
|
||||
|
||||
$renderException = function (\Throwable $e) use ($output) {
|
||||
if ($output instanceof ConsoleOutputInterface) {
|
||||
@@ -169,8 +173,11 @@ class Application implements ResetInterface
|
||||
|
||||
try {
|
||||
$exitCode = $this->doRun($input, $output);
|
||||
} catch (\Exception $e) {
|
||||
if (!$this->catchExceptions) {
|
||||
} catch (\Throwable $e) {
|
||||
if ($e instanceof \Exception && !$this->catchExceptions) {
|
||||
throw $e;
|
||||
}
|
||||
if (!$e instanceof \Exception && !$this->catchErrors) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
@@ -228,7 +235,7 @@ class Application implements ResetInterface
|
||||
try {
|
||||
// Makes ArgvInput::getFirstArgument() able to distinguish an option from an argument.
|
||||
$input->bind($this->getDefinition());
|
||||
} catch (ExceptionInterface $e) {
|
||||
} catch (ExceptionInterface) {
|
||||
// Errors must be ignored, full binding/validation happens later when the command is known.
|
||||
}
|
||||
|
||||
@@ -258,7 +265,26 @@ class Application implements ResetInterface
|
||||
// the command name MUST be the first element of the input
|
||||
$command = $this->find($name);
|
||||
} catch (\Throwable $e) {
|
||||
if (!($e instanceof CommandNotFoundException && !$e instanceof NamespaceNotFoundException) || 1 !== \count($alternatives = $e->getAlternatives()) || !$input->isInteractive()) {
|
||||
if (($e instanceof CommandNotFoundException && !$e instanceof NamespaceNotFoundException) && 1 === \count($alternatives = $e->getAlternatives()) && $input->isInteractive()) {
|
||||
$alternative = $alternatives[0];
|
||||
|
||||
$style = new SymfonyStyle($input, $output);
|
||||
$output->writeln('');
|
||||
$formattedBlock = (new FormatterHelper())->formatBlock(sprintf('Command "%s" is not defined.', $name), 'error', true);
|
||||
$output->writeln($formattedBlock);
|
||||
if (!$style->confirm(sprintf('Do you want to run "%s" instead? ', $alternative), false)) {
|
||||
if (null !== $this->dispatcher) {
|
||||
$event = new ConsoleErrorEvent($input, $output, $e);
|
||||
$this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
|
||||
|
||||
return $event->getExitCode();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$command = $this->find($alternative);
|
||||
} else {
|
||||
if (null !== $this->dispatcher) {
|
||||
$event = new ConsoleErrorEvent($input, $output, $e);
|
||||
$this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
|
||||
@@ -270,27 +296,24 @@ class Application implements ResetInterface
|
||||
$e = $event->getError();
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
try {
|
||||
if ($e instanceof CommandNotFoundException && $namespace = $this->findNamespace($name)) {
|
||||
$helper = new DescriptorHelper();
|
||||
$helper->describe($output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output, $this, [
|
||||
'format' => 'txt',
|
||||
'raw_text' => false,
|
||||
'namespace' => $namespace,
|
||||
'short' => false,
|
||||
]);
|
||||
|
||||
$alternative = $alternatives[0];
|
||||
return isset($event) ? $event->getExitCode() : 1;
|
||||
}
|
||||
|
||||
$style = new SymfonyStyle($input, $output);
|
||||
$output->writeln('');
|
||||
$formattedBlock = (new FormatterHelper())->formatBlock(sprintf('Command "%s" is not defined.', $name), 'error', true);
|
||||
$output->writeln($formattedBlock);
|
||||
if (!$style->confirm(sprintf('Do you want to run "%s" instead? ', $alternative), false)) {
|
||||
if (null !== $this->dispatcher) {
|
||||
$event = new ConsoleErrorEvent($input, $output, $e);
|
||||
$this->dispatcher->dispatch($event, ConsoleEvents::ERROR);
|
||||
|
||||
return $event->getExitCode();
|
||||
throw $e;
|
||||
} catch (NamespaceNotFoundException) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
$command = $this->find($alternative);
|
||||
}
|
||||
|
||||
if ($command instanceof LazyCommand) {
|
||||
@@ -305,12 +328,15 @@ class Application implements ResetInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @return void
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setHelperSet(HelperSet $helperSet)
|
||||
{
|
||||
$this->helperSet = $helperSet;
|
||||
@@ -318,18 +344,15 @@ class Application implements ResetInterface
|
||||
|
||||
/**
|
||||
* Get the helper set associated with the command.
|
||||
*
|
||||
* @return HelperSet
|
||||
*/
|
||||
public function getHelperSet()
|
||||
public function getHelperSet(): HelperSet
|
||||
{
|
||||
if (!$this->helperSet) {
|
||||
$this->helperSet = $this->getDefaultHelperSet();
|
||||
}
|
||||
|
||||
return $this->helperSet;
|
||||
return $this->helperSet ??= $this->getDefaultHelperSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setDefinition(InputDefinition $definition)
|
||||
{
|
||||
$this->definition = $definition;
|
||||
@@ -337,14 +360,10 @@ class Application implements ResetInterface
|
||||
|
||||
/**
|
||||
* Gets the InputDefinition related to this Application.
|
||||
*
|
||||
* @return InputDefinition
|
||||
*/
|
||||
public function getDefinition()
|
||||
public function getDefinition(): InputDefinition
|
||||
{
|
||||
if (!$this->definition) {
|
||||
$this->definition = $this->getDefaultInputDefinition();
|
||||
}
|
||||
$this->definition ??= $this->getDefaultInputDefinition();
|
||||
|
||||
if ($this->singleCommand) {
|
||||
$inputDefinition = $this->definition;
|
||||
@@ -365,18 +384,16 @@ class Application implements ResetInterface
|
||||
CompletionInput::TYPE_ARGUMENT_VALUE === $input->getCompletionType()
|
||||
&& 'command' === $input->getCompletionName()
|
||||
) {
|
||||
$commandNames = [];
|
||||
foreach ($this->all() as $name => $command) {
|
||||
// skip hidden commands and aliased commands as they already get added below
|
||||
if ($command->isHidden() || $command->getName() !== $name) {
|
||||
continue;
|
||||
}
|
||||
$commandNames[] = $command->getName();
|
||||
$suggestions->suggestValue(new Suggestion($command->getName(), $command->getDescription()));
|
||||
foreach ($command->getAliases() as $name) {
|
||||
$commandNames[] = $name;
|
||||
$suggestions->suggestValue(new Suggestion($name, $command->getDescription()));
|
||||
}
|
||||
}
|
||||
$suggestions->suggestValues(array_filter($commandNames));
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -390,26 +407,24 @@ class Application implements ResetInterface
|
||||
|
||||
/**
|
||||
* Gets the help message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHelp()
|
||||
public function getHelp(): string
|
||||
{
|
||||
return $this->getLongVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether to catch exceptions or not during commands execution.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function areExceptionsCaught()
|
||||
public function areExceptionsCaught(): bool
|
||||
{
|
||||
return $this->catchExceptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to catch exceptions or not during commands execution.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setCatchExceptions(bool $boolean)
|
||||
{
|
||||
@@ -417,17 +432,25 @@ class Application implements ResetInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether to automatically exit after a command execution or not.
|
||||
*
|
||||
* @return bool
|
||||
* Sets whether to catch errors or not during commands execution.
|
||||
*/
|
||||
public function isAutoExitEnabled()
|
||||
public function setCatchErrors(bool $catchErrors = true): void
|
||||
{
|
||||
$this->catchErrors = $catchErrors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether to automatically exit after a command execution or not.
|
||||
*/
|
||||
public function isAutoExitEnabled(): bool
|
||||
{
|
||||
return $this->autoExit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to automatically exit after a command execution or not.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setAutoExit(bool $boolean)
|
||||
{
|
||||
@@ -436,17 +459,17 @@ class Application implements ResetInterface
|
||||
|
||||
/**
|
||||
* Gets the name of the application.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the application name.
|
||||
**/
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setName(string $name)
|
||||
{
|
||||
$this->name = $name;
|
||||
@@ -454,16 +477,16 @@ class Application implements ResetInterface
|
||||
|
||||
/**
|
||||
* Gets the application version.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVersion()
|
||||
public function getVersion(): string
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the application version.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setVersion(string $version)
|
||||
{
|
||||
@@ -490,10 +513,8 @@ class Application implements ResetInterface
|
||||
|
||||
/**
|
||||
* Registers a new command.
|
||||
*
|
||||
* @return Command
|
||||
*/
|
||||
public function register(string $name)
|
||||
public function register(string $name): Command
|
||||
{
|
||||
return $this->add(new Command($name));
|
||||
}
|
||||
@@ -504,6 +525,8 @@ class Application implements ResetInterface
|
||||
* If a Command is not enabled it will not be added.
|
||||
*
|
||||
* @param Command[] $commands An array of commands
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addCommands(array $commands)
|
||||
{
|
||||
@@ -586,14 +609,12 @@ class Application implements ResetInterface
|
||||
|
||||
/**
|
||||
* Returns true if the command exists, false otherwise.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has(string $name)
|
||||
public function has(string $name): bool
|
||||
{
|
||||
$this->init();
|
||||
|
||||
return isset($this->commands[$name]) || ($this->commandLoader && $this->commandLoader->has($name) && $this->add($this->commandLoader->get($name)));
|
||||
return isset($this->commands[$name]) || ($this->commandLoader?->has($name) && $this->add($this->commandLoader->get($name)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -603,7 +624,7 @@ class Application implements ResetInterface
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getNamespaces()
|
||||
public function getNamespaces(): array
|
||||
{
|
||||
$namespaces = [];
|
||||
foreach ($this->all() as $command) {
|
||||
@@ -624,11 +645,9 @@ class Application implements ResetInterface
|
||||
/**
|
||||
* Finds a registered namespace by a name or an abbreviation.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws NamespaceNotFoundException When namespace is incorrect or ambiguous
|
||||
*/
|
||||
public function findNamespace(string $namespace)
|
||||
public function findNamespace(string $namespace): string
|
||||
{
|
||||
$allNamespaces = $this->getNamespaces();
|
||||
$expr = implode('[^:]*:', array_map('preg_quote', explode(':', $namespace))).'[^:]*';
|
||||
@@ -705,9 +724,7 @@ class Application implements ResetInterface
|
||||
|
||||
if ($alternatives = $this->findAlternatives($name, $allCommands)) {
|
||||
// remove hidden commands
|
||||
$alternatives = array_filter($alternatives, function ($name) {
|
||||
return !$this->get($name)->isHidden();
|
||||
});
|
||||
$alternatives = array_filter($alternatives, fn ($name) => !$this->get($name)->isHidden());
|
||||
|
||||
if (1 == \count($alternatives)) {
|
||||
$message .= "\n\nDid you mean this?\n ";
|
||||
@@ -820,7 +837,7 @@ class Application implements ResetInterface
|
||||
*
|
||||
* @return string[][]
|
||||
*/
|
||||
public static function getAbbreviations(array $names)
|
||||
public static function getAbbreviations(array $names): array
|
||||
{
|
||||
$abbrevs = [];
|
||||
foreach ($names as $name) {
|
||||
@@ -858,9 +875,7 @@ class Application implements ResetInterface
|
||||
}
|
||||
|
||||
if (str_contains($message, "@anonymous\0")) {
|
||||
$message = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', function ($m) {
|
||||
return class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0];
|
||||
}, $message);
|
||||
$message = preg_replace_callback('/[a-zA-Z_\x7f-\xff][\\\\a-zA-Z0-9_\x7f-\xff]*+@anonymous\x00.*?\.php(?:0x?|:[0-9]++\$)[0-9a-fA-F]++/', fn ($m) => class_exists($m[0], false) ? (get_parent_class($m[0]) ?: key(class_implements($m[0])) ?: 'class').'@anonymous' : $m[0], $message);
|
||||
}
|
||||
|
||||
$width = $this->terminal->getWidth() ? $this->terminal->getWidth() - 1 : \PHP_INT_MAX;
|
||||
@@ -921,6 +936,8 @@ class Application implements ResetInterface
|
||||
|
||||
/**
|
||||
* Configures the input and output instances based on the user arguments and options.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function configureIO(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
@@ -995,44 +1012,65 @@ class Application implements ResetInterface
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->signalsToDispatchEvent) {
|
||||
$commandSignals = $command instanceof SignalableCommandInterface ? $command->getSubscribedSignals() : [];
|
||||
$commandSignals = $command instanceof SignalableCommandInterface ? $command->getSubscribedSignals() : [];
|
||||
if ($commandSignals || $this->dispatcher && $this->signalsToDispatchEvent) {
|
||||
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.');
|
||||
}
|
||||
|
||||
if ($commandSignals || null !== $this->dispatcher) {
|
||||
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.');
|
||||
}
|
||||
if (Terminal::hasSttyAvailable()) {
|
||||
$sttyMode = shell_exec('stty -g');
|
||||
|
||||
if (Terminal::hasSttyAvailable()) {
|
||||
$sttyMode = shell_exec('stty -g');
|
||||
|
||||
foreach ([\SIGINT, \SIGTERM] as $signal) {
|
||||
$this->signalRegistry->register($signal, static function () use ($sttyMode) {
|
||||
shell_exec('stty '.$sttyMode);
|
||||
});
|
||||
}
|
||||
foreach ([\SIGINT, \SIGTERM] as $signal) {
|
||||
$this->signalRegistry->register($signal, static fn () => shell_exec('stty '.$sttyMode));
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $this->dispatcher) {
|
||||
if ($this->dispatcher) {
|
||||
// We register application signals, so that we can dispatch the event
|
||||
foreach ($this->signalsToDispatchEvent as $signal) {
|
||||
$event = new ConsoleSignalEvent($command, $input, $output, $signal);
|
||||
|
||||
$this->signalRegistry->register($signal, function ($signal, $hasNext) use ($event) {
|
||||
$this->signalRegistry->register($signal, function ($signal) use ($event, $command, $commandSignals) {
|
||||
$this->dispatcher->dispatch($event, ConsoleEvents::SIGNAL);
|
||||
$exitCode = $event->getExitCode();
|
||||
|
||||
// No more handlers, we try to simulate PHP default behavior
|
||||
if (!$hasNext) {
|
||||
if (!\in_array($signal, [\SIGUSR1, \SIGUSR2], true)) {
|
||||
exit(0);
|
||||
// If the command is signalable, we call the handleSignal() method
|
||||
if (\in_array($signal, $commandSignals, true)) {
|
||||
$exitCode = $command->handleSignal($signal, $exitCode);
|
||||
// BC layer for Symfony <= 5
|
||||
if (null === $exitCode) {
|
||||
trigger_deprecation('symfony/console', '6.3', 'Not returning an exit code from "%s::handleSignal()" is deprecated, return "false" to keep the command running or "0" to exit successfully.', get_debug_type($command));
|
||||
$exitCode = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (false !== $exitCode) {
|
||||
$event = new ConsoleTerminateEvent($command, $event->getInput(), $event->getOutput(), $exitCode, $signal);
|
||||
$this->dispatcher->dispatch($event, ConsoleEvents::TERMINATE);
|
||||
|
||||
exit($event->getExitCode());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// then we register command signals, but not if already handled after the dispatcher
|
||||
$commandSignals = array_diff($commandSignals, $this->signalsToDispatchEvent);
|
||||
}
|
||||
|
||||
foreach ($commandSignals as $signal) {
|
||||
$this->signalRegistry->register($signal, [$command, 'handleSignal']);
|
||||
$this->signalRegistry->register($signal, function (int $signal) use ($command): void {
|
||||
$exitCode = $command->handleSignal($signal);
|
||||
// BC layer for Symfony <= 5
|
||||
if (null === $exitCode) {
|
||||
trigger_deprecation('symfony/console', '6.3', 'Not returning an exit code from "%s::handleSignal()" is deprecated, return "false" to keep the command running or "0" to exit successfully.', get_debug_type($command));
|
||||
$exitCode = 0;
|
||||
}
|
||||
|
||||
if (false !== $exitCode) {
|
||||
exit($exitCode);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1044,7 +1082,7 @@ class Application implements ResetInterface
|
||||
try {
|
||||
$command->mergeApplicationDefinition();
|
||||
$input->bind($command->getDefinition());
|
||||
} catch (ExceptionInterface $e) {
|
||||
} catch (ExceptionInterface) {
|
||||
// ignore invalid options/arguments for now, to allow the event listeners to customize the InputDefinition
|
||||
}
|
||||
|
||||
@@ -1081,20 +1119,16 @@ class Application implements ResetInterface
|
||||
|
||||
/**
|
||||
* Gets the name of the command based on input.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function getCommandName(InputInterface $input)
|
||||
protected function getCommandName(InputInterface $input): ?string
|
||||
{
|
||||
return $this->singleCommand ? $this->defaultCommand : $input->getFirstArgument();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default input definition.
|
||||
*
|
||||
* @return InputDefinition
|
||||
*/
|
||||
protected function getDefaultInputDefinition()
|
||||
protected function getDefaultInputDefinition(): InputDefinition
|
||||
{
|
||||
return new InputDefinition([
|
||||
new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
|
||||
@@ -1112,17 +1146,15 @@ class Application implements ResetInterface
|
||||
*
|
||||
* @return Command[]
|
||||
*/
|
||||
protected function getDefaultCommands()
|
||||
protected function getDefaultCommands(): array
|
||||
{
|
||||
return [new HelpCommand(), new ListCommand(), new CompleteCommand(), new DumpCompletionCommand()];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default helper set with the helpers that should always be available.
|
||||
*
|
||||
* @return HelperSet
|
||||
*/
|
||||
protected function getDefaultHelperSet()
|
||||
protected function getDefaultHelperSet(): HelperSet
|
||||
{
|
||||
return new HelperSet([
|
||||
new FormatterHelper(),
|
||||
@@ -1144,10 +1176,8 @@ class Application implements ResetInterface
|
||||
* Returns the namespace part of the command name.
|
||||
*
|
||||
* This method is not part of public API and should not be used directly.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function extractNamespace(string $name, int $limit = null)
|
||||
public function extractNamespace(string $name, int $limit = null): string
|
||||
{
|
||||
$parts = explode(':', $name, -1);
|
||||
|
||||
@@ -1196,7 +1226,7 @@ class Application implements ResetInterface
|
||||
}
|
||||
}
|
||||
|
||||
$alternatives = array_filter($alternatives, function ($lev) use ($threshold) { return $lev < 2 * $threshold; });
|
||||
$alternatives = array_filter($alternatives, fn ($lev) => $lev < 2 * $threshold);
|
||||
ksort($alternatives, \SORT_NATURAL | \SORT_FLAG_CASE);
|
||||
|
||||
return array_keys($alternatives);
|
||||
@@ -1207,7 +1237,7 @@ class Application implements ResetInterface
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDefaultCommand(string $commandName, bool $isSingleCommand = false)
|
||||
public function setDefaultCommand(string $commandName, bool $isSingleCommand = false): static
|
||||
{
|
||||
$this->defaultCommand = explode('|', ltrim($commandName, '|'))[0];
|
||||
|
||||
@@ -1287,7 +1317,7 @@ class Application implements ResetInterface
|
||||
return $namespaces;
|
||||
}
|
||||
|
||||
private function init()
|
||||
private function init(): void
|
||||
{
|
||||
if ($this->initialized) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user