upgraded dependencies

This commit is contained in:
RafficMohammed
2023-01-08 01:59:16 +05:30
parent 51056e3aad
commit f9ae387337
6895 changed files with 133617 additions and 178680 deletions

View File

@@ -12,16 +12,24 @@
namespace Symfony\Component\Console;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Command\CompleteCommand;
use Symfony\Component\Console\Command\DumpCompletionCommand;
use Symfony\Component\Console\Command\HelpCommand;
use Symfony\Component\Console\Command\LazyCommand;
use Symfony\Component\Console\Command\ListCommand;
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\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Symfony\Component\Console\Event\ConsoleSignalEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\Console\Exception\CommandNotFoundException;
use Symfony\Component\Console\Exception\ExceptionInterface;
use Symfony\Component\Console\Exception\LogicException;
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\FormatterHelper;
@@ -39,12 +47,10 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\SignalRegistry\SignalRegistry;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Debug\ErrorHandler as LegacyErrorHandler;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Symfony\Component\ErrorHandler\ErrorHandler;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Service\ResetInterface;
/**
@@ -79,25 +85,27 @@ class Application implements ResetInterface
private $defaultCommand;
private $singleCommand = false;
private $initialized;
private $signalRegistry;
private $signalsToDispatchEvent = [];
/**
* @param string $name The name of the application
* @param string $version The version of the application
*/
public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN')
{
$this->name = $name;
$this->version = $version;
$this->terminal = new Terminal();
$this->defaultCommand = 'list';
if (\defined('SIGINT') && SignalRegistry::isSupported()) {
$this->signalRegistry = new SignalRegistry();
$this->signalsToDispatchEvent = [\SIGINT, \SIGTERM, \SIGUSR1, \SIGUSR2];
}
}
/**
* @final since Symfony 4.3, the type-hint will be updated to the interface from symfony/contracts in 5.0
* @final
*/
public function setDispatcher(EventDispatcherInterface $dispatcher)
{
$this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher);
$this->dispatcher = $dispatcher;
}
public function setCommandLoader(CommandLoaderInterface $commandLoader)
@@ -105,6 +113,20 @@ class Application implements ResetInterface
$this->commandLoader = $commandLoader;
}
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.');
}
return $this->signalRegistry;
}
public function setSignalsToDispatchEvent(int ...$signalsToDispatchEvent)
{
$this->signalsToDispatchEvent = $signalsToDispatchEvent;
}
/**
* Runs the current application.
*
@@ -136,7 +158,7 @@ class Application implements ResetInterface
};
if ($phpHandler = set_exception_handler($renderException)) {
restore_exception_handler();
if (!\is_array($phpHandler) || (!$phpHandler[0] instanceof ErrorHandler && !$phpHandler[0] instanceof LegacyErrorHandler)) {
if (!\is_array($phpHandler) || !$phpHandler[0] instanceof ErrorHandler) {
$errorHandler = true;
} elseif ($errorHandler = $phpHandler[0]->setExceptionHandler($renderException)) {
$phpHandler[0]->setExceptionHandler($errorHandler);
@@ -271,6 +293,10 @@ class Application implements ResetInterface
$command = $this->find($alternative);
}
if ($command instanceof LazyCommand) {
$command = $command->getCommand();
}
$this->runningCommand = $command;
$exitCode = $this->doRunCommand($command, $input, $output);
$this->runningCommand = null;
@@ -293,7 +319,7 @@ class Application implements ResetInterface
/**
* Get the helper set associated with the command.
*
* @return HelperSet The HelperSet instance associated with this command
* @return HelperSet
*/
public function getHelperSet()
{
@@ -312,7 +338,7 @@ class Application implements ResetInterface
/**
* Gets the InputDefinition related to this Application.
*
* @return InputDefinition The InputDefinition instance
* @return InputDefinition
*/
public function getDefinition()
{
@@ -330,10 +356,42 @@ class Application implements ResetInterface
return $this->definition;
}
/**
* Adds suggestions to $suggestions for the current completion input (e.g. option or argument).
*/
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
if (
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();
foreach ($command->getAliases() as $name) {
$commandNames[] = $name;
}
}
$suggestions->suggestValues(array_filter($commandNames));
return;
}
if (CompletionInput::TYPE_OPTION_NAME === $input->getCompletionType()) {
$suggestions->suggestOptions($this->getDefinition()->getOptions());
return;
}
}
/**
* Gets the help message.
*
* @return string A help message
* @return string
*/
public function getHelp()
{
@@ -343,7 +401,7 @@ class Application implements ResetInterface
/**
* Gets whether to catch exceptions or not during commands execution.
*
* @return bool Whether to catch exceptions or not during commands execution
* @return bool
*/
public function areExceptionsCaught()
{
@@ -352,18 +410,16 @@ class Application implements ResetInterface
/**
* Sets whether to catch exceptions or not during commands execution.
*
* @param bool $boolean Whether to catch exceptions or not during commands execution
*/
public function setCatchExceptions($boolean)
public function setCatchExceptions(bool $boolean)
{
$this->catchExceptions = (bool) $boolean;
$this->catchExceptions = $boolean;
}
/**
* Gets whether to automatically exit after a command execution or not.
*
* @return bool Whether to automatically exit after a command execution or not
* @return bool
*/
public function isAutoExitEnabled()
{
@@ -372,18 +428,16 @@ class Application implements ResetInterface
/**
* Sets whether to automatically exit after a command execution or not.
*
* @param bool $boolean Whether to automatically exit after a command execution or not
*/
public function setAutoExit($boolean)
public function setAutoExit(bool $boolean)
{
$this->autoExit = (bool) $boolean;
$this->autoExit = $boolean;
}
/**
* Gets the name of the application.
*
* @return string The application name
* @return string
*/
public function getName()
{
@@ -392,10 +446,8 @@ class Application implements ResetInterface
/**
* Sets the application name.
*
* @param string $name The application name
*/
public function setName($name)
**/
public function setName(string $name)
{
$this->name = $name;
}
@@ -403,7 +455,7 @@ class Application implements ResetInterface
/**
* Gets the application version.
*
* @return string The application version
* @return string
*/
public function getVersion()
{
@@ -412,10 +464,8 @@ class Application implements ResetInterface
/**
* Sets the application version.
*
* @param string $version The application version
*/
public function setVersion($version)
public function setVersion(string $version)
{
$this->version = $version;
}
@@ -423,7 +473,7 @@ class Application implements ResetInterface
/**
* Returns the long version of the application.
*
* @return string The long application version
* @return string
*/
public function getLongVersion()
{
@@ -441,11 +491,9 @@ class Application implements ResetInterface
/**
* Registers a new command.
*
* @param string $name The command name
*
* @return Command The newly created command
* @return Command
*/
public function register($name)
public function register(string $name)
{
return $this->add(new Command($name));
}
@@ -470,7 +518,7 @@ class Application implements ResetInterface
* If a command with the same name already exists, it will be overridden.
* If the command is not enabled it will not be added.
*
* @return Command|null The registered command if enabled or null
* @return Command|null
*/
public function add(Command $command)
{
@@ -484,11 +532,13 @@ class Application implements ResetInterface
return null;
}
// Will throw if the command is not correctly initialized.
$command->getDefinition();
if (!$command instanceof LazyCommand) {
// Will throw if the command is not correctly initialized.
$command->getDefinition();
}
if (!$command->getName()) {
throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', \get_class($command)));
throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', get_debug_type($command)));
}
$this->commands[$command->getName()] = $command;
@@ -503,13 +553,11 @@ class Application implements ResetInterface
/**
* Returns a registered command by name or alias.
*
* @param string $name The command name or alias
*
* @return Command A Command object
* @return Command
*
* @throws CommandNotFoundException When given command name does not exist
*/
public function get($name)
public function get(string $name)
{
$this->init();
@@ -539,11 +587,9 @@ class Application implements ResetInterface
/**
* Returns true if the command exists, false otherwise.
*
* @param string $name The command name or alias
*
* @return bool true if the command exists, false otherwise
* @return bool
*/
public function has($name)
public function has(string $name)
{
$this->init();
@@ -555,7 +601,7 @@ class Application implements ResetInterface
*
* It does not return the global namespace which always exists.
*
* @return string[] An array of namespaces
* @return string[]
*/
public function getNamespaces()
{
@@ -565,29 +611,27 @@ class Application implements ResetInterface
continue;
}
$namespaces = array_merge($namespaces, $this->extractAllNamespaces($command->getName()));
$namespaces[] = $this->extractAllNamespaces($command->getName());
foreach ($command->getAliases() as $alias) {
$namespaces = array_merge($namespaces, $this->extractAllNamespaces($alias));
$namespaces[] = $this->extractAllNamespaces($alias);
}
}
return array_values(array_unique(array_filter($namespaces)));
return array_values(array_unique(array_filter(array_merge([], ...$namespaces))));
}
/**
* Finds a registered namespace by a name or an abbreviation.
*
* @param string $namespace A namespace or abbreviation to search for
*
* @return string A registered namespace
* @return string
*
* @throws NamespaceNotFoundException When namespace is incorrect or ambiguous
*/
public function findNamespace($namespace)
public function findNamespace(string $namespace)
{
$allNamespaces = $this->getNamespaces();
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $namespace);
$expr = implode('[^:]*:', array_map('preg_quote', explode(':', $namespace))).'[^:]*';
$namespaces = preg_grep('{^'.$expr.'}', $allNamespaces);
if (empty($namespaces)) {
@@ -620,13 +664,11 @@ class Application implements ResetInterface
* Contrary to get, this command tries to find the best
* match if you give it an abbreviation of a name or alias.
*
* @param string $name A command name or a command alias
*
* @return Command A Command instance
* @return Command
*
* @throws CommandNotFoundException When command name is incorrect or ambiguous
*/
public function find($name)
public function find(string $name)
{
$this->init();
@@ -645,7 +687,7 @@ class Application implements ResetInterface
}
$allCommands = $this->commandLoader ? array_merge($this->commandLoader->getNames(), array_keys($this->commands)) : array_keys($this->commands);
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $name);
$expr = implode('[^:]*:', array_map('preg_quote', explode(':', $name))).'[^:]*';
$commands = preg_grep('{^'.$expr.'}', $allCommands);
if (empty($commands)) {
@@ -699,7 +741,7 @@ class Application implements ResetInterface
$abbrevs = array_values($commands);
$maxLen = 0;
foreach ($abbrevs as $abbrev) {
$maxLen = max(Helper::strlen($abbrev), $maxLen);
$maxLen = max(Helper::width($abbrev), $maxLen);
}
$abbrevs = array_map(function ($cmd) use ($commandList, $usableWidth, $maxLen, &$commands) {
if ($commandList[$cmd]->isHidden()) {
@@ -710,7 +752,7 @@ class Application implements ResetInterface
$abbrev = str_pad($cmd, $maxLen, ' ').' '.$commandList[$cmd]->getDescription();
return Helper::strlen($abbrev) > $usableWidth ? Helper::substr($abbrev, 0, $usableWidth - 3).'...' : $abbrev;
return Helper::width($abbrev) > $usableWidth ? Helper::substr($abbrev, 0, $usableWidth - 3).'...' : $abbrev;
}, array_values($commands));
if (\count($commands) > 1) {
@@ -723,7 +765,7 @@ class Application implements ResetInterface
$command = $this->get(reset($commands));
if ($command->isHidden()) {
@trigger_error(sprintf('Command "%s" is hidden, finding it using an abbreviation is deprecated since Symfony 4.4, use its full name instead.', $command->getName()), \E_USER_DEPRECATED);
throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $name));
}
return $command;
@@ -734,11 +776,9 @@ class Application implements ResetInterface
*
* The array keys are the full names and the values the command instances.
*
* @param string $namespace A namespace name
*
* @return Command[] An array of Command instances
* @return Command[]
*/
public function all($namespace = null)
public function all(string $namespace = null)
{
$this->init();
@@ -778,11 +818,9 @@ class Application implements ResetInterface
/**
* Returns an array of possible abbreviations given a set of names.
*
* @param array $names An array of names
*
* @return array An array of abbreviations
* @return string[][]
*/
public static function getAbbreviations($names)
public static function getAbbreviations(array $names)
{
$abbrevs = [];
foreach ($names as $name) {
@@ -795,86 +833,26 @@ class Application implements ResetInterface
return $abbrevs;
}
/**
* Renders a caught exception.
*
* @deprecated since Symfony 4.4, use "renderThrowable()" instead
*/
public function renderException(\Exception $e, OutputInterface $output)
{
@trigger_error(sprintf('The "%s::renderException()" method is deprecated since Symfony 4.4, use "renderThrowable()" instead.', __CLASS__), \E_USER_DEPRECATED);
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
$this->doRenderException($e, $output);
$this->finishRenderThrowableOrException($output);
}
public function renderThrowable(\Throwable $e, OutputInterface $output): void
{
if (__CLASS__ !== static::class && __CLASS__ === (new \ReflectionMethod($this, 'renderThrowable'))->getDeclaringClass()->getName() && __CLASS__ !== (new \ReflectionMethod($this, 'renderException'))->getDeclaringClass()->getName()) {
@trigger_error(sprintf('The "%s::renderException()" method is deprecated since Symfony 4.4, use "renderThrowable()" instead.', __CLASS__), \E_USER_DEPRECATED);
if (!$e instanceof \Exception) {
$e = class_exists(FatalThrowableError::class) ? new FatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), \E_ERROR, $e->getFile(), $e->getLine());
}
$this->renderException($e, $output);
return;
}
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
$this->doRenderThrowable($e, $output);
$this->finishRenderThrowableOrException($output);
}
private function finishRenderThrowableOrException(OutputInterface $output): void
{
if (null !== $this->runningCommand) {
$output->writeln(sprintf('<info>%s</info>', OutputFormatter::escape(sprintf($this->runningCommand->getSynopsis(), $this->getName()))), OutputInterface::VERBOSITY_QUIET);
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
}
}
/**
* @deprecated since Symfony 4.4, use "doRenderThrowable()" instead
*/
protected function doRenderException(\Exception $e, OutputInterface $output)
{
@trigger_error(sprintf('The "%s::doRenderException()" method is deprecated since Symfony 4.4, use "doRenderThrowable()" instead.', __CLASS__), \E_USER_DEPRECATED);
$this->doActuallyRenderThrowable($e, $output);
}
protected function doRenderThrowable(\Throwable $e, OutputInterface $output): void
{
if (__CLASS__ !== static::class && __CLASS__ === (new \ReflectionMethod($this, 'doRenderThrowable'))->getDeclaringClass()->getName() && __CLASS__ !== (new \ReflectionMethod($this, 'doRenderException'))->getDeclaringClass()->getName()) {
@trigger_error(sprintf('The "%s::doRenderException()" method is deprecated since Symfony 4.4, use "doRenderThrowable()" instead.', __CLASS__), \E_USER_DEPRECATED);
if (!$e instanceof \Exception) {
$e = class_exists(FatalThrowableError::class) ? new FatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), \E_ERROR, $e->getFile(), $e->getLine());
}
$this->doRenderException($e, $output);
return;
}
$this->doActuallyRenderThrowable($e, $output);
}
private function doActuallyRenderThrowable(\Throwable $e, OutputInterface $output): void
{
do {
$message = trim($e->getMessage());
if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
$class = get_debug_type($e);
$title = sprintf(' [%s%s] ', $class, 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : '');
$len = Helper::strlen($title);
$len = Helper::width($title);
} else {
$len = 0;
}
@@ -890,7 +868,7 @@ class Application implements ResetInterface
foreach ('' !== $message ? preg_split('/\r?\n/', $message) : [] as $line) {
foreach ($this->splitStringByWidth($line, $width - 4) as $line) {
// pre-format lines to get the right string length
$lineLength = Helper::strlen($line) + 4;
$lineLength = Helper::width($line) + 4;
$lines[] = [$line, $lineLength];
$len = max($lineLength, $len);
@@ -903,7 +881,7 @@ class Application implements ResetInterface
}
$messages[] = $emptyLine = sprintf('<error>%s</error>', str_repeat(' ', $len));
if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
$messages[] = sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - Helper::strlen($title))));
$messages[] = sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - Helper::width($title))));
}
foreach ($lines as $line) {
$messages[] = sprintf('<error> %s %s</error>', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1]));
@@ -1017,6 +995,47 @@ class Application implements ResetInterface
}
}
if ($this->signalsToDispatchEvent) {
$commandSignals = $command instanceof SignalableCommandInterface ? $command->getSubscribedSignals() : [];
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');
foreach ([\SIGINT, \SIGTERM] as $signal) {
$this->signalRegistry->register($signal, static function () use ($sttyMode) {
shell_exec('stty '.$sttyMode);
});
}
}
}
if (null !== $this->dispatcher) {
foreach ($this->signalsToDispatchEvent as $signal) {
$event = new ConsoleSignalEvent($command, $input, $output, $signal);
$this->signalRegistry->register($signal, function ($signal, $hasNext) use ($event) {
$this->dispatcher->dispatch($event, ConsoleEvents::SIGNAL);
// No more handlers, we try to simulate PHP default behavior
if (!$hasNext) {
if (!\in_array($signal, [\SIGUSR1, \SIGUSR2], true)) {
exit(0);
}
}
});
}
}
foreach ($commandSignals as $signal) {
$this->signalRegistry->register($signal, [$command, 'handleSignal']);
}
}
if (null === $this->dispatcher) {
return $command->run($input, $output);
}
@@ -1073,19 +1092,17 @@ class Application implements ResetInterface
/**
* Gets the default input definition.
*
* @return InputDefinition An InputDefinition instance
* @return InputDefinition
*/
protected function getDefaultInputDefinition()
{
return new InputDefinition([
new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message'),
new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display help for the given command. When no command is given display help for the <info>'.$this->defaultCommand.'</info> command'),
new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message'),
new InputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'),
new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this application version'),
new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output'),
new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output'),
new InputOption('--ansi', '', InputOption::VALUE_NEGATABLE, 'Force (or disable --no-ansi) ANSI output', null),
new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question'),
]);
}
@@ -1093,17 +1110,17 @@ class Application implements ResetInterface
/**
* Gets the default commands that should always be available.
*
* @return Command[] An array of default Command instances
* @return Command[]
*/
protected function getDefaultCommands()
{
return [new HelpCommand(), new ListCommand()];
return [new HelpCommand(), new ListCommand(), new CompleteCommand(), new DumpCompletionCommand()];
}
/**
* Gets the default helper set with the helpers that should always be available.
*
* @return HelperSet A HelperSet instance
* @return HelperSet
*/
protected function getDefaultHelperSet()
{
@@ -1128,12 +1145,9 @@ class Application implements ResetInterface
*
* This method is not part of public API and should not be used directly.
*
* @param string $name The full name of the command
* @param string $limit The maximum number of parts of the namespace
*
* @return string The namespace of the command
* @return string
*/
public function extractNamespace($name, $limit = null)
public function extractNamespace(string $name, int $limit = null)
{
$parts = explode(':', $name, -1);
@@ -1144,7 +1158,7 @@ class Application implements ResetInterface
* Finds alternative of $name among $collection,
* if nothing is found in $collection, try in $abbrevs.
*
* @return string[] A sorted array of similar string
* @return string[]
*/
private function findAlternatives(string $name, iterable $collection): array
{
@@ -1191,14 +1205,11 @@ class Application implements ResetInterface
/**
* Sets the default Command name.
*
* @param string $commandName The Command name
* @param bool $isSingleCommand Set to true if there is only one command in this application
*
* @return self
* @return $this
*/
public function setDefaultCommand($commandName, $isSingleCommand = false)
public function setDefaultCommand(string $commandName, bool $isSingleCommand = false)
{
$this->defaultCommand = $commandName;
$this->defaultCommand = explode('|', ltrim($commandName, '|'))[0];
if ($isSingleCommand) {
// Ensure the command exist
@@ -1257,7 +1268,7 @@ class Application implements ResetInterface
/**
* Returns all namespaces of the command name.
*
* @return string[] The namespaces of the command
* @return string[]
*/
private function extractAllNamespaces(string $name): array
{