Upgrade framework

This commit is contained in:
2023-11-14 16:54:35 +01:00
parent 1648a5cd42
commit 4fcf6fffcc
10548 changed files with 693138 additions and 466698 deletions

View File

@@ -19,20 +19,14 @@ 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>
*/
class ArrayInput extends Input
{
private $parameters;
private array $parameters;
/**
* Constructor.
*
* @param array $parameters An array of parameters
* @param InputDefinition|null $definition A InputDefinition instance
*/
public function __construct(array $parameters, InputDefinition $definition = null)
{
$this->parameters = $parameters;
@@ -43,34 +37,36 @@ class ArrayInput extends Input
/**
* {@inheritdoc}
*/
public function getFirstArgument()
public function getFirstArgument(): ?string
{
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;
}
/**
* {@inheritdoc}
*/
public function hasParameterOption($values, $onlyParams = false)
public function hasParameterOption(string|array $values, bool $onlyParams = false): bool
{
$values = (array) $values;
foreach ($this->parameters as $k => $v) {
if (!is_int($k)) {
if (!\is_int($k)) {
$v = $k;
}
if ($onlyParams && $v === '--') {
if ($onlyParams && '--' === $v) {
return false;
}
if (in_array($v, $values)) {
if (\in_array($v, $values)) {
return true;
}
}
@@ -81,20 +77,20 @@ class ArrayInput extends Input
/**
* {@inheritdoc}
*/
public function getParameterOption($values, $default = false, $onlyParams = false)
public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false): mixed
{
$values = (array) $values;
foreach ($this->parameters as $k => $v) {
if ($onlyParams && ($k === '--' || (is_int($k) && $v === '--'))) {
return false;
if ($onlyParams && ('--' === $k || (\is_int($k) && '--' === $v))) {
return $default;
}
if (is_int($k)) {
if (in_array($v, $values)) {
if (\is_int($k)) {
if (\in_array($v, $values)) {
return true;
}
} elseif (in_array($k, $values)) {
} elseif (\in_array($k, $values)) {
return $v;
}
}
@@ -104,17 +100,22 @@ class ArrayInput extends Input
/**
* Returns a stringified representation of the args passed to the command.
*
* @return string
*/
public function __toString()
public function __toString(): string
{
$params = array();
$params = [];
foreach ($this->parameters as $param => $val) {
if ($param && '-' === $param[0]) {
$params[] = $param.('' != $val ? '='.$this->escapeToken($val) : '');
if ($param && \is_string($param) && '-' === $param[0]) {
$glue = ('-' === $param[1]) ? '=' : ' ';
if (\is_array($val)) {
foreach ($val as $v) {
$params[] = $param.('' != $v ? $glue.$this->escapeToken($v) : '');
}
} else {
$params[] = $param.('' != $val ? $glue.$this->escapeToken($val) : '');
}
} else {
$params[] = $this->escapeToken($val);
$params[] = \is_array($val) ? implode(' ', array_map([$this, 'escapeToken'], $val)) : $this->escapeToken($val);
}
}
@@ -127,12 +128,12 @@ class ArrayInput extends Input
protected function parse()
{
foreach ($this->parameters as $key => $value) {
if ($key === '--') {
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 +144,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, mixed $value)
{
if (!$this->definition->hasShortcut($shortcut)) {
throw new InvalidOptionException(sprintf('The "-%s" option does not exist.', $shortcut));
@@ -160,16 +158,20 @@ 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, mixed $value)
{
if (!$this->definition->hasOption($name)) {
throw new InvalidOptionException(sprintf('The "--%s" option does not exist.', $name));
if (!$this->definition->hasNegation($name)) {
throw new InvalidOptionException(sprintf('The "--%s" option does not exist.', $name));
}
$optionName = $this->definition->negationToName($name);
$this->options[$optionName] = false;
return;
}
$option = $this->definition->getOption($name);
@@ -190,12 +192,9 @@ class ArrayInput extends Input
/**
* Adds an argument value.
*
* @param string $name The argument name
* @param mixed $value The value for the argument
*
* @throws InvalidArgumentException When argument given doesn't exist
*/
private function addArgument($name, $value)
private function addArgument(string|int $name, mixed $value)
{
if (!$this->definition->hasArgument($name)) {
throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));