Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/updater.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/console/Input/ArrayInput.php')
-rw-r--r--vendor/symfony/console/Input/ArrayInput.php69
1 files changed, 34 insertions, 35 deletions
diff --git a/vendor/symfony/console/Input/ArrayInput.php b/vendor/symfony/console/Input/ArrayInput.php
index a44b6b2..30bd205 100644
--- a/vendor/symfony/console/Input/ArrayInput.php
+++ b/vendor/symfony/console/Input/ArrayInput.php
@@ -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>
*/
@@ -27,12 +27,6 @@ class ArrayInput extends Input
{
private $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;
@@ -45,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;
}
/**
@@ -62,15 +58,15 @@ class ArrayInput extends Input
$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;
}
}
@@ -86,15 +82,15 @@ class ArrayInput extends Input
$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;
}
}
@@ -109,12 +105,19 @@ class ArrayInput extends Input
*/
public function __toString()
{
- $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 +130,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 +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));
@@ -179,7 +176,9 @@ class ArrayInput extends Input
throw new InvalidOptionException(sprintf('The "--%s" option requires a value.', $name));
}
- $value = $option->isValueOptional() ? $option->getDefault() : true;
+ if (!$option->isValueOptional()) {
+ $value = true;
+ }
}
$this->options[$name] = $value;
@@ -188,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
*/