updated-packages
This commit is contained in:
74
vendor/symfony/console/Input/ArgvInput.php
vendored
74
vendor/symfony/console/Input/ArgvInput.php
vendored
@@ -44,14 +44,11 @@ class ArgvInput extends Input
|
||||
private $parsed;
|
||||
|
||||
/**
|
||||
* @param array|null $argv An array of parameters from the CLI (in the argv format)
|
||||
* @param InputDefinition|null $definition A InputDefinition instance
|
||||
* @param array|null $argv An array of parameters from the CLI (in the argv format)
|
||||
*/
|
||||
public function __construct(array $argv = null, InputDefinition $definition = null)
|
||||
{
|
||||
if (null === $argv) {
|
||||
$argv = $_SERVER['argv'];
|
||||
}
|
||||
$argv = $argv ?? $_SERVER['argv'] ?? [];
|
||||
|
||||
// strip the application name
|
||||
array_shift($argv);
|
||||
@@ -78,7 +75,7 @@ class ArgvInput extends Input
|
||||
$this->parseArgument($token);
|
||||
} elseif ($parseOptions && '--' == $token) {
|
||||
$parseOptions = false;
|
||||
} elseif ($parseOptions && 0 === strpos($token, '--')) {
|
||||
} elseif ($parseOptions && str_starts_with($token, '--')) {
|
||||
$this->parseLongOption($token);
|
||||
} elseif ($parseOptions && '-' === $token[0] && '-' !== $token) {
|
||||
$this->parseShortOption($token);
|
||||
@@ -90,10 +87,8 @@ class ArgvInput extends Input
|
||||
|
||||
/**
|
||||
* Parses a short option.
|
||||
*
|
||||
* @param string $token The current token
|
||||
*/
|
||||
private function parseShortOption($token)
|
||||
private function parseShortOption(string $token)
|
||||
{
|
||||
$name = substr($token, 1);
|
||||
|
||||
@@ -112,11 +107,9 @@ class ArgvInput extends Input
|
||||
/**
|
||||
* Parses a short option set.
|
||||
*
|
||||
* @param string $name The current token
|
||||
*
|
||||
* @throws RuntimeException When option given doesn't exist
|
||||
*/
|
||||
private function parseShortOptionSet($name)
|
||||
private function parseShortOptionSet(string $name)
|
||||
{
|
||||
$len = \strlen($name);
|
||||
for ($i = 0; $i < $len; ++$i) {
|
||||
@@ -138,15 +131,13 @@ class ArgvInput extends Input
|
||||
|
||||
/**
|
||||
* Parses a long option.
|
||||
*
|
||||
* @param string $token The current token
|
||||
*/
|
||||
private function parseLongOption($token)
|
||||
private function parseLongOption(string $token)
|
||||
{
|
||||
$name = substr($token, 2);
|
||||
|
||||
if (false !== $pos = strpos($name, '=')) {
|
||||
if (0 === \strlen($value = substr($name, $pos + 1))) {
|
||||
if ('' === $value = substr($name, $pos + 1)) {
|
||||
array_unshift($this->parsed, $value);
|
||||
}
|
||||
$this->addLongOption(substr($name, 0, $pos), $value);
|
||||
@@ -158,18 +149,16 @@ class ArgvInput extends Input
|
||||
/**
|
||||
* Parses an argument.
|
||||
*
|
||||
* @param string $token The current token
|
||||
*
|
||||
* @throws RuntimeException When too many arguments are given
|
||||
*/
|
||||
private function parseArgument($token)
|
||||
private function parseArgument(string $token)
|
||||
{
|
||||
$c = \count($this->arguments);
|
||||
|
||||
// if input is expecting another argument, add it
|
||||
if ($this->definition->hasArgument($c)) {
|
||||
$arg = $this->definition->getArgument($c);
|
||||
$this->arguments[$arg->getName()] = $arg->isArray() ? array($token) : $token;
|
||||
$this->arguments[$arg->getName()] = $arg->isArray() ? [$token] : $token;
|
||||
|
||||
// if last argument isArray(), append token to last argument
|
||||
} elseif ($this->definition->hasArgument($c - 1) && $this->definition->getArgument($c - 1)->isArray()) {
|
||||
@@ -190,12 +179,9 @@ class ArgvInput extends Input
|
||||
/**
|
||||
* Adds a short option value.
|
||||
*
|
||||
* @param string $shortcut The short option key
|
||||
* @param mixed $value The value for the option
|
||||
*
|
||||
* @throws RuntimeException When option given doesn't exist
|
||||
*/
|
||||
private function addShortOption($shortcut, $value)
|
||||
private function addShortOption(string $shortcut, $value)
|
||||
{
|
||||
if (!$this->definition->hasShortcut($shortcut)) {
|
||||
throw new RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut));
|
||||
@@ -207,12 +193,9 @@ class ArgvInput extends Input
|
||||
/**
|
||||
* Adds a long option value.
|
||||
*
|
||||
* @param string $name The long option key
|
||||
* @param mixed $value The value for the option
|
||||
*
|
||||
* @throws RuntimeException When option given doesn't exist
|
||||
*/
|
||||
private function addLongOption($name, $value)
|
||||
private function addLongOption(string $name, $value)
|
||||
{
|
||||
if (!$this->definition->hasOption($name)) {
|
||||
throw new RuntimeException(sprintf('The "--%s" option does not exist.', $name));
|
||||
@@ -224,11 +207,11 @@ class ArgvInput extends Input
|
||||
throw new RuntimeException(sprintf('The "--%s" option does not accept a value.', $name));
|
||||
}
|
||||
|
||||
if (\in_array($value, array('', null), true) && $option->acceptValue() && \count($this->parsed)) {
|
||||
if (\in_array($value, ['', null], true) && $option->acceptValue() && \count($this->parsed)) {
|
||||
// if option accepts an optional or mandatory argument
|
||||
// let's see if there is one provided
|
||||
$next = array_shift($this->parsed);
|
||||
if ((isset($next[0]) && '-' !== $next[0]) || \in_array($next, array('', null), true)) {
|
||||
if ((isset($next[0]) && '-' !== $next[0]) || \in_array($next, ['', null], true)) {
|
||||
$value = $next;
|
||||
} else {
|
||||
array_unshift($this->parsed, $next);
|
||||
@@ -257,13 +240,34 @@ class ArgvInput extends Input
|
||||
*/
|
||||
public function getFirstArgument()
|
||||
{
|
||||
foreach ($this->tokens as $token) {
|
||||
$isOption = false;
|
||||
foreach ($this->tokens as $i => $token) {
|
||||
if ($token && '-' === $token[0]) {
|
||||
if (str_contains($token, '=') || !isset($this->tokens[$i + 1])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If it's a long option, consider that everything after "--" is the option name.
|
||||
// Otherwise, use the last char (if it's a short option set, only the last one can take a value with space separator)
|
||||
$name = '-' === $token[1] ? substr($token, 2) : substr($token, -1);
|
||||
if (!isset($this->options[$name]) && !$this->definition->hasShortcut($name)) {
|
||||
// noop
|
||||
} elseif ((isset($this->options[$name]) || isset($this->options[$name = $this->definition->shortcutToName($name)])) && $this->tokens[$i + 1] === $this->options[$name]) {
|
||||
$isOption = true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($isOption) {
|
||||
$isOption = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -281,8 +285,8 @@ class ArgvInput extends Input
|
||||
// Options with values:
|
||||
// For long options, test for '--option=' at beginning
|
||||
// For short options, test for '-o' at beginning
|
||||
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
|
||||
if ($token === $value || '' !== $leading && 0 === strpos($token, $leading)) {
|
||||
$leading = str_starts_with($value, '--') ? $value.'=' : $value;
|
||||
if ($token === $value || '' !== $leading && str_starts_with($token, $leading)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -312,8 +316,8 @@ class ArgvInput extends Input
|
||||
// Options with values:
|
||||
// For long options, test for '--option=' at beginning
|
||||
// For short options, test for '-o' at beginning
|
||||
$leading = 0 === strpos($value, '--') ? $value.'=' : $value;
|
||||
if ('' !== $leading && 0 === strpos($token, $leading)) {
|
||||
$leading = str_starts_with($value, '--') ? $value.'=' : $value;
|
||||
if ('' !== $leading && str_starts_with($token, $leading)) {
|
||||
return substr($token, \strlen($leading));
|
||||
}
|
||||
}
|
||||
|
37
vendor/symfony/console/Input/ArrayInput.php
vendored
37
vendor/symfony/console/Input/ArrayInput.php
vendored
@@ -19,7 +19,7 @@ use Symfony\Component\Console\Exception\InvalidOptionException;
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* $input = new ArrayInput(array('name' => 'foo', '--bar' => 'foobar'));
|
||||
* $input = new ArrayInput(['command' => 'foo:bar', 'foo' => 'bar', '--bar' => 'foobar']);
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
@@ -39,13 +39,15 @@ class ArrayInput extends Input
|
||||
*/
|
||||
public function getFirstArgument()
|
||||
{
|
||||
foreach ($this->parameters as $key => $value) {
|
||||
if ($key && '-' === $key[0]) {
|
||||
foreach ($this->parameters as $param => $value) {
|
||||
if ($param && \is_string($param) && '-' === $param[0]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,18 +105,19 @@ class ArrayInput extends Input
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$params = array();
|
||||
$params = [];
|
||||
foreach ($this->parameters as $param => $val) {
|
||||
if ($param && '-' === $param[0]) {
|
||||
if ($param && \is_string($param) && '-' === $param[0]) {
|
||||
$glue = ('-' === $param[1]) ? '=' : ' ';
|
||||
if (\is_array($val)) {
|
||||
foreach ($val as $v) {
|
||||
$params[] = $param.('' != $v ? '='.$this->escapeToken($v) : '');
|
||||
$params[] = $param.('' != $v ? $glue.$this->escapeToken($v) : '');
|
||||
}
|
||||
} else {
|
||||
$params[] = $param.('' != $val ? '='.$this->escapeToken($val) : '');
|
||||
$params[] = $param.('' != $val ? $glue.$this->escapeToken($val) : '');
|
||||
}
|
||||
} else {
|
||||
$params[] = \is_array($val) ? implode(' ', array_map(array($this, 'escapeToken'), $val)) : $this->escapeToken($val);
|
||||
$params[] = \is_array($val) ? implode(' ', array_map([$this, 'escapeToken'], $val)) : $this->escapeToken($val);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,9 +133,9 @@ class ArrayInput extends Input
|
||||
if ('--' === $key) {
|
||||
return;
|
||||
}
|
||||
if (0 === strpos($key, '--')) {
|
||||
if (str_starts_with($key, '--')) {
|
||||
$this->addLongOption(substr($key, 2), $value);
|
||||
} elseif ('-' === $key[0]) {
|
||||
} elseif (str_starts_with($key, '-')) {
|
||||
$this->addShortOption(substr($key, 1), $value);
|
||||
} else {
|
||||
$this->addArgument($key, $value);
|
||||
@@ -143,12 +146,9 @@ class ArrayInput extends Input
|
||||
/**
|
||||
* Adds a short option value.
|
||||
*
|
||||
* @param string $shortcut The short option key
|
||||
* @param mixed $value The value for the option
|
||||
*
|
||||
* @throws InvalidOptionException When option given doesn't exist
|
||||
*/
|
||||
private function addShortOption($shortcut, $value)
|
||||
private function addShortOption(string $shortcut, $value)
|
||||
{
|
||||
if (!$this->definition->hasShortcut($shortcut)) {
|
||||
throw new InvalidOptionException(sprintf('The "-%s" option does not exist.', $shortcut));
|
||||
@@ -160,13 +160,10 @@ class ArrayInput extends Input
|
||||
/**
|
||||
* Adds a long option value.
|
||||
*
|
||||
* @param string $name The long option key
|
||||
* @param mixed $value The value for the option
|
||||
*
|
||||
* @throws InvalidOptionException When option given doesn't exist
|
||||
* @throws InvalidOptionException When a required value is missing
|
||||
*/
|
||||
private function addLongOption($name, $value)
|
||||
private function addLongOption(string $name, $value)
|
||||
{
|
||||
if (!$this->definition->hasOption($name)) {
|
||||
throw new InvalidOptionException(sprintf('The "--%s" option does not exist.', $name));
|
||||
@@ -190,8 +187,8 @@ class ArrayInput extends Input
|
||||
/**
|
||||
* Adds an argument value.
|
||||
*
|
||||
* @param string $name The argument name
|
||||
* @param mixed $value The value for the argument
|
||||
* @param string|int $name The argument name
|
||||
* @param mixed $value The value for the argument
|
||||
*
|
||||
* @throws InvalidArgumentException When argument given doesn't exist
|
||||
*/
|
||||
|
20
vendor/symfony/console/Input/Input.php
vendored
20
vendor/symfony/console/Input/Input.php
vendored
@@ -29,8 +29,8 @@ abstract class Input implements InputInterface, StreamableInputInterface
|
||||
{
|
||||
protected $definition;
|
||||
protected $stream;
|
||||
protected $options = array();
|
||||
protected $arguments = array();
|
||||
protected $options = [];
|
||||
protected $arguments = [];
|
||||
protected $interactive = true;
|
||||
|
||||
public function __construct(InputDefinition $definition = null)
|
||||
@@ -48,8 +48,8 @@ abstract class Input implements InputInterface, StreamableInputInterface
|
||||
*/
|
||||
public function bind(InputDefinition $definition)
|
||||
{
|
||||
$this->arguments = array();
|
||||
$this->options = array();
|
||||
$this->arguments = [];
|
||||
$this->options = [];
|
||||
$this->definition = $definition;
|
||||
|
||||
$this->parse();
|
||||
@@ -69,7 +69,7 @@ abstract class Input implements InputInterface, StreamableInputInterface
|
||||
$givenArguments = $this->arguments;
|
||||
|
||||
$missingArguments = array_filter(array_keys($definition->getArguments()), function ($argument) use ($definition, $givenArguments) {
|
||||
return !array_key_exists($argument, $givenArguments) && $definition->getArgument($argument)->isRequired();
|
||||
return !\array_key_exists($argument, $givenArguments) && $definition->getArgument($argument)->isRequired();
|
||||
});
|
||||
|
||||
if (\count($missingArguments) > 0) {
|
||||
@@ -106,11 +106,11 @@ abstract class Input implements InputInterface, StreamableInputInterface
|
||||
*/
|
||||
public function getArgument($name)
|
||||
{
|
||||
if (!$this->definition->hasArgument($name)) {
|
||||
if (!$this->definition->hasArgument((string) $name)) {
|
||||
throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
||||
}
|
||||
|
||||
return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault();
|
||||
return $this->arguments[$name] ?? $this->definition->getArgument($name)->getDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,7 +118,7 @@ abstract class Input implements InputInterface, StreamableInputInterface
|
||||
*/
|
||||
public function setArgument($name, $value)
|
||||
{
|
||||
if (!$this->definition->hasArgument($name)) {
|
||||
if (!$this->definition->hasArgument((string) $name)) {
|
||||
throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ abstract class Input implements InputInterface, StreamableInputInterface
|
||||
*/
|
||||
public function hasArgument($name)
|
||||
{
|
||||
return $this->definition->hasArgument($name);
|
||||
return $this->definition->hasArgument((string) $name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,7 +150,7 @@ abstract class Input implements InputInterface, StreamableInputInterface
|
||||
throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
|
||||
}
|
||||
|
||||
return array_key_exists($name, $this->options) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
|
||||
return \array_key_exists($name, $this->options) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
|
22
vendor/symfony/console/Input/InputArgument.php
vendored
22
vendor/symfony/console/Input/InputArgument.php
vendored
@@ -21,9 +21,9 @@ use Symfony\Component\Console\Exception\LogicException;
|
||||
*/
|
||||
class InputArgument
|
||||
{
|
||||
const REQUIRED = 1;
|
||||
const OPTIONAL = 2;
|
||||
const IS_ARRAY = 4;
|
||||
public const REQUIRED = 1;
|
||||
public const OPTIONAL = 2;
|
||||
public const IS_ARRAY = 4;
|
||||
|
||||
private $name;
|
||||
private $mode;
|
||||
@@ -31,10 +31,10 @@ class InputArgument
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* @param string $name The argument name
|
||||
* @param int|null $mode The argument mode: self::REQUIRED or self::OPTIONAL
|
||||
* @param string $description A description text
|
||||
* @param string|string[]|null $default The default value (for self::OPTIONAL mode only)
|
||||
* @param string $name The argument name
|
||||
* @param int|null $mode The argument mode: self::REQUIRED or self::OPTIONAL
|
||||
* @param string $description A description text
|
||||
* @param string|bool|int|float|array|null $default The default value (for self::OPTIONAL mode only)
|
||||
*
|
||||
* @throws InvalidArgumentException When argument mode is not valid
|
||||
*/
|
||||
@@ -86,19 +86,19 @@ class InputArgument
|
||||
/**
|
||||
* Sets the default value.
|
||||
*
|
||||
* @param string|string[]|null $default The default value
|
||||
* @param string|bool|int|float|array|null $default
|
||||
*
|
||||
* @throws LogicException When incorrect default value is given
|
||||
*/
|
||||
public function setDefault($default = null)
|
||||
{
|
||||
if (self::REQUIRED === $this->mode && null !== $default) {
|
||||
if ($this->isRequired() && null !== $default) {
|
||||
throw new LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
|
||||
}
|
||||
|
||||
if ($this->isArray()) {
|
||||
if (null === $default) {
|
||||
$default = array();
|
||||
$default = [];
|
||||
} elseif (!\is_array($default)) {
|
||||
throw new LogicException('A default value for an array argument must be an array.');
|
||||
}
|
||||
@@ -110,7 +110,7 @@ class InputArgument
|
||||
/**
|
||||
* Returns the default value.
|
||||
*
|
||||
* @return string|string[]|null The default value
|
||||
* @return string|bool|int|float|array|null
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
|
48
vendor/symfony/console/Input/InputDefinition.php
vendored
48
vendor/symfony/console/Input/InputDefinition.php
vendored
@@ -19,10 +19,10 @@ use Symfony\Component\Console\Exception\LogicException;
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* $definition = new InputDefinition(array(
|
||||
* $definition = new InputDefinition([
|
||||
* new InputArgument('name', InputArgument::REQUIRED),
|
||||
* new InputOption('foo', 'f', InputOption::VALUE_REQUIRED),
|
||||
* ));
|
||||
* ]);
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
@@ -38,7 +38,7 @@ class InputDefinition
|
||||
/**
|
||||
* @param array $definition An array of InputArgument and InputOption instance
|
||||
*/
|
||||
public function __construct(array $definition = array())
|
||||
public function __construct(array $definition = [])
|
||||
{
|
||||
$this->setDefinition($definition);
|
||||
}
|
||||
@@ -48,8 +48,8 @@ class InputDefinition
|
||||
*/
|
||||
public function setDefinition(array $definition)
|
||||
{
|
||||
$arguments = array();
|
||||
$options = array();
|
||||
$arguments = [];
|
||||
$options = [];
|
||||
foreach ($definition as $item) {
|
||||
if ($item instanceof InputOption) {
|
||||
$options[] = $item;
|
||||
@@ -67,9 +67,9 @@ class InputDefinition
|
||||
*
|
||||
* @param InputArgument[] $arguments An array of InputArgument objects
|
||||
*/
|
||||
public function setArguments($arguments = array())
|
||||
public function setArguments($arguments = [])
|
||||
{
|
||||
$this->arguments = array();
|
||||
$this->arguments = [];
|
||||
$this->requiredCount = 0;
|
||||
$this->hasOptional = false;
|
||||
$this->hasAnArrayArgument = false;
|
||||
@@ -81,7 +81,7 @@ class InputDefinition
|
||||
*
|
||||
* @param InputArgument[] $arguments An array of InputArgument objects
|
||||
*/
|
||||
public function addArguments($arguments = array())
|
||||
public function addArguments($arguments = [])
|
||||
{
|
||||
if (null !== $arguments) {
|
||||
foreach ($arguments as $argument) {
|
||||
@@ -171,7 +171,7 @@ class InputDefinition
|
||||
*/
|
||||
public function getArgumentCount()
|
||||
{
|
||||
return $this->hasAnArrayArgument ? PHP_INT_MAX : \count($this->arguments);
|
||||
return $this->hasAnArrayArgument ? \PHP_INT_MAX : \count($this->arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,13 +185,11 @@ class InputDefinition
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default values.
|
||||
*
|
||||
* @return array An array of default values
|
||||
* @return array<string|bool|int|float|array|null>
|
||||
*/
|
||||
public function getArgumentDefaults()
|
||||
{
|
||||
$values = array();
|
||||
$values = [];
|
||||
foreach ($this->arguments as $argument) {
|
||||
$values[$argument->getName()] = $argument->getDefault();
|
||||
}
|
||||
@@ -204,10 +202,10 @@ class InputDefinition
|
||||
*
|
||||
* @param InputOption[] $options An array of InputOption objects
|
||||
*/
|
||||
public function setOptions($options = array())
|
||||
public function setOptions($options = [])
|
||||
{
|
||||
$this->options = array();
|
||||
$this->shortcuts = array();
|
||||
$this->options = [];
|
||||
$this->shortcuts = [];
|
||||
$this->addOptions($options);
|
||||
}
|
||||
|
||||
@@ -216,7 +214,7 @@ class InputDefinition
|
||||
*
|
||||
* @param InputOption[] $options An array of InputOption objects
|
||||
*/
|
||||
public function addOptions($options = array())
|
||||
public function addOptions($options = [])
|
||||
{
|
||||
foreach ($options as $option) {
|
||||
$this->addOption($option);
|
||||
@@ -316,13 +314,11 @@ class InputDefinition
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of default values.
|
||||
*
|
||||
* @return array An array of all default values
|
||||
* @return array<string|bool|int|float|array|null>
|
||||
*/
|
||||
public function getOptionDefaults()
|
||||
{
|
||||
$values = array();
|
||||
$values = [];
|
||||
foreach ($this->options as $option) {
|
||||
$values[$option->getName()] = $option->getDefault();
|
||||
}
|
||||
@@ -333,13 +329,11 @@ class InputDefinition
|
||||
/**
|
||||
* Returns the InputOption name given a shortcut.
|
||||
*
|
||||
* @param string $shortcut The shortcut
|
||||
*
|
||||
* @return string The InputOption name
|
||||
*
|
||||
* @throws InvalidArgumentException When option given does not exist
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
private function shortcutToName($shortcut)
|
||||
public function shortcutToName(string $shortcut): string
|
||||
{
|
||||
if (!isset($this->shortcuts[$shortcut])) {
|
||||
throw new InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
|
||||
@@ -357,7 +351,7 @@ class InputDefinition
|
||||
*/
|
||||
public function getSynopsis($short = false)
|
||||
{
|
||||
$elements = array();
|
||||
$elements = [];
|
||||
|
||||
if ($short && $this->getOptions()) {
|
||||
$elements[] = '[options]';
|
||||
|
24
vendor/symfony/console/Input/InputInterface.php
vendored
24
vendor/symfony/console/Input/InputInterface.php
vendored
@@ -51,9 +51,9 @@ interface InputInterface
|
||||
* Does not necessarily return the correct result for short options
|
||||
* when multiple flags are combined in the same option.
|
||||
*
|
||||
* @param string|array $values The value(s) to look for in the raw parameters (can be an array)
|
||||
* @param mixed $default The default value to return if no result is found
|
||||
* @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal
|
||||
* @param string|array $values The value(s) to look for in the raw parameters (can be an array)
|
||||
* @param string|bool|int|float|array|null $default The default value to return if no result is found
|
||||
* @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal
|
||||
*
|
||||
* @return mixed The option value
|
||||
*/
|
||||
@@ -76,7 +76,7 @@ interface InputInterface
|
||||
/**
|
||||
* Returns all the given arguments merged with the default values.
|
||||
*
|
||||
* @return array
|
||||
* @return array<string|bool|int|float|array|null>
|
||||
*/
|
||||
public function getArguments();
|
||||
|
||||
@@ -85,7 +85,7 @@ interface InputInterface
|
||||
*
|
||||
* @param string $name The argument name
|
||||
*
|
||||
* @return string|string[]|null The argument value
|
||||
* @return mixed
|
||||
*
|
||||
* @throws InvalidArgumentException When argument given doesn't exist
|
||||
*/
|
||||
@@ -94,8 +94,8 @@ interface InputInterface
|
||||
/**
|
||||
* Sets an argument value by name.
|
||||
*
|
||||
* @param string $name The argument name
|
||||
* @param string|string[]|null $value The argument value
|
||||
* @param string $name The argument name
|
||||
* @param mixed $value The argument value
|
||||
*
|
||||
* @throws InvalidArgumentException When argument given doesn't exist
|
||||
*/
|
||||
@@ -104,7 +104,7 @@ interface InputInterface
|
||||
/**
|
||||
* Returns true if an InputArgument object exists by name or position.
|
||||
*
|
||||
* @param string|int $name The InputArgument name or position
|
||||
* @param string $name The argument name
|
||||
*
|
||||
* @return bool true if the InputArgument object exists, false otherwise
|
||||
*/
|
||||
@@ -113,7 +113,7 @@ interface InputInterface
|
||||
/**
|
||||
* Returns all the given options merged with the default values.
|
||||
*
|
||||
* @return array
|
||||
* @return array<string|bool|int|float|array|null>
|
||||
*/
|
||||
public function getOptions();
|
||||
|
||||
@@ -122,7 +122,7 @@ interface InputInterface
|
||||
*
|
||||
* @param string $name The option name
|
||||
*
|
||||
* @return string|string[]|bool|null The option value
|
||||
* @return mixed
|
||||
*
|
||||
* @throws InvalidArgumentException When option given doesn't exist
|
||||
*/
|
||||
@@ -131,8 +131,8 @@ interface InputInterface
|
||||
/**
|
||||
* Sets an option value by name.
|
||||
*
|
||||
* @param string $name The option name
|
||||
* @param string|string[]|bool|null $value The option value
|
||||
* @param string $name The option name
|
||||
* @param mixed $value The option value
|
||||
*
|
||||
* @throws InvalidArgumentException When option given doesn't exist
|
||||
*/
|
||||
|
47
vendor/symfony/console/Input/InputOption.php
vendored
47
vendor/symfony/console/Input/InputOption.php
vendored
@@ -21,10 +21,25 @@ use Symfony\Component\Console\Exception\LogicException;
|
||||
*/
|
||||
class InputOption
|
||||
{
|
||||
const VALUE_NONE = 1;
|
||||
const VALUE_REQUIRED = 2;
|
||||
const VALUE_OPTIONAL = 4;
|
||||
const VALUE_IS_ARRAY = 8;
|
||||
/**
|
||||
* Do not accept input for the option (e.g. --yell). This is the default behavior of options.
|
||||
*/
|
||||
public const VALUE_NONE = 1;
|
||||
|
||||
/**
|
||||
* A value must be passed when the option is used (e.g. --iterations=5 or -i5).
|
||||
*/
|
||||
public const VALUE_REQUIRED = 2;
|
||||
|
||||
/**
|
||||
* The option may or may not have a value (e.g. --yell or --yell=loud).
|
||||
*/
|
||||
public const VALUE_OPTIONAL = 4;
|
||||
|
||||
/**
|
||||
* The option accepts multiple values (e.g. --dir=/foo --dir=/bar).
|
||||
*/
|
||||
public const VALUE_IS_ARRAY = 8;
|
||||
|
||||
private $name;
|
||||
private $shortcut;
|
||||
@@ -33,17 +48,17 @@ class InputOption
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* @param string $name The option name
|
||||
* @param string|array $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
|
||||
* @param int|null $mode The option mode: One of the VALUE_* constants
|
||||
* @param string $description A description text
|
||||
* @param string|string[]|int|bool|null $default The default value (must be null for self::VALUE_NONE)
|
||||
* @param string $name The option name
|
||||
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
|
||||
* @param int|null $mode The option mode: One of the VALUE_* constants
|
||||
* @param string $description A description text
|
||||
* @param string|bool|int|float|array|null $default The default value (must be null for self::VALUE_NONE)
|
||||
*
|
||||
* @throws InvalidArgumentException If option mode is invalid or incompatible
|
||||
*/
|
||||
public function __construct(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null)
|
||||
{
|
||||
if (0 === strpos($name, '--')) {
|
||||
if (str_starts_with($name, '--')) {
|
||||
$name = substr($name, 2);
|
||||
}
|
||||
|
||||
@@ -89,7 +104,7 @@ class InputOption
|
||||
/**
|
||||
* Returns the option shortcut.
|
||||
*
|
||||
* @return string The shortcut
|
||||
* @return string|null The shortcut
|
||||
*/
|
||||
public function getShortcut()
|
||||
{
|
||||
@@ -147,11 +162,7 @@ class InputOption
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default value.
|
||||
*
|
||||
* @param string|string[]|int|bool|null $default The default value
|
||||
*
|
||||
* @throws LogicException When incorrect default value is given
|
||||
* @param string|bool|int|float|array|null $default
|
||||
*/
|
||||
public function setDefault($default = null)
|
||||
{
|
||||
@@ -161,7 +172,7 @@ class InputOption
|
||||
|
||||
if ($this->isArray()) {
|
||||
if (null === $default) {
|
||||
$default = array();
|
||||
$default = [];
|
||||
} elseif (!\is_array($default)) {
|
||||
throw new LogicException('A default value for an array option must be an array.');
|
||||
}
|
||||
@@ -173,7 +184,7 @@ class InputOption
|
||||
/**
|
||||
* Returns the default value.
|
||||
*
|
||||
* @return string|string[]|int|bool|null The default value
|
||||
* @return string|bool|int|float|array|null
|
||||
*/
|
||||
public function getDefault()
|
||||
{
|
||||
|
46
vendor/symfony/console/Input/StringInput.php
vendored
46
vendor/symfony/console/Input/StringInput.php
vendored
@@ -24,15 +24,16 @@ use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||
*/
|
||||
class StringInput extends ArgvInput
|
||||
{
|
||||
const REGEX_STRING = '([^\s]+?)(?:\s|(?<!\\\\)"|(?<!\\\\)\'|$)';
|
||||
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')';
|
||||
public const REGEX_STRING = '([^\s]+?)(?:\s|(?<!\\\\)"|(?<!\\\\)\'|$)';
|
||||
public const REGEX_UNQUOTED_STRING = '([^\s\\\\]+?)';
|
||||
public const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')';
|
||||
|
||||
/**
|
||||
* @param string $input A string representing the parameters from the CLI
|
||||
*/
|
||||
public function __construct(string $input)
|
||||
{
|
||||
parent::__construct(array());
|
||||
parent::__construct([]);
|
||||
|
||||
$this->setTokens($this->tokenize($input));
|
||||
}
|
||||
@@ -40,33 +41,44 @@ class StringInput extends ArgvInput
|
||||
/**
|
||||
* Tokenizes a string.
|
||||
*
|
||||
* @param string $input The input to tokenize
|
||||
*
|
||||
* @return array An array of tokens
|
||||
*
|
||||
* @throws InvalidArgumentException When unable to parse input (should never happen)
|
||||
*/
|
||||
private function tokenize($input)
|
||||
private function tokenize(string $input): array
|
||||
{
|
||||
$tokens = array();
|
||||
$tokens = [];
|
||||
$length = \strlen($input);
|
||||
$cursor = 0;
|
||||
$token = null;
|
||||
while ($cursor < $length) {
|
||||
if (preg_match('/\s+/A', $input, $match, null, $cursor)) {
|
||||
} elseif (preg_match('/([^="\'\s]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, null, $cursor)) {
|
||||
$tokens[] = $match[1].$match[2].stripcslashes(str_replace(array('"\'', '\'"', '\'\'', '""'), '', substr($match[3], 1, \strlen($match[3]) - 2)));
|
||||
} elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, null, $cursor)) {
|
||||
$tokens[] = stripcslashes(substr($match[0], 1, \strlen($match[0]) - 2));
|
||||
} elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, null, $cursor)) {
|
||||
$tokens[] = stripcslashes($match[1]);
|
||||
if ('\\' === $input[$cursor]) {
|
||||
$token .= $input[++$cursor] ?? '';
|
||||
++$cursor;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match('/\s+/A', $input, $match, 0, $cursor)) {
|
||||
if (null !== $token) {
|
||||
$tokens[] = $token;
|
||||
$token = null;
|
||||
}
|
||||
} elseif (preg_match('/([^="\'\s]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, 0, $cursor)) {
|
||||
$token .= $match[1].$match[2].stripcslashes(str_replace(['"\'', '\'"', '\'\'', '""'], '', substr($match[3], 1, -1)));
|
||||
} elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, 0, $cursor)) {
|
||||
$token .= stripcslashes(substr($match[0], 1, -1));
|
||||
} elseif (preg_match('/'.self::REGEX_UNQUOTED_STRING.'/A', $input, $match, 0, $cursor)) {
|
||||
$token .= $match[1];
|
||||
} else {
|
||||
// should never happen
|
||||
throw new InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10)));
|
||||
throw new InvalidArgumentException(sprintf('Unable to parse input near "... %s ...".', substr($input, $cursor, 10)));
|
||||
}
|
||||
|
||||
$cursor += \strlen($match[0]);
|
||||
}
|
||||
|
||||
if (null !== $token) {
|
||||
$tokens[] = $token;
|
||||
}
|
||||
|
||||
return $tokens;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user