'foo:bar', 'foo' => 'bar', '--bar' => 'foobar']); * * @author Fabien Potencier */ class ArrayInput extends Input { private $parameters; public function __construct(array $parameters, InputDefinition $definition = null) { $this->parameters = $parameters; parent::__construct($definition); } /** * {@inheritdoc} */ public function getFirstArgument() { foreach ($this->parameters as $param => $value) { if ($param && \is_string($param) && '-' === $param[0]) { continue; } return $value; } return null; } /** * {@inheritdoc} */ public function hasParameterOption($values, bool $onlyParams = false) { $values = (array) $values; foreach ($this->parameters as $k => $v) { if (!\is_int($k)) { $v = $k; } if ($onlyParams && '--' === $v) { return false; } if (\in_array($v, $values)) { return true; } } return false; } /** * {@inheritdoc} */ public function getParameterOption($values, $default = false, bool $onlyParams = false) { $values = (array) $values; foreach ($this->parameters as $k => $v) { if ($onlyParams && ('--' === $k || (\is_int($k) && '--' === $v))) { return $default; } if (\is_int($k)) { if (\in_array($v, $values)) { return true; } } elseif (\in_array($k, $values)) { return $v; } } return $default; } /** * Returns a stringified representation of the args passed to the command. * * @return string */ public function __toString() { $params = []; foreach ($this->parameters as $param => $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[] = \is_array($val) ? implode(' ', array_map([$this, 'escapeToken'], $val)) : $this->escapeToken($val); } } return implode(' ', $params); } /** * {@inheritdoc} */ protected function parse() { foreach ($this->parameters as $key => $value) { if ('--' === $key) { return; } if (str_starts_with($key, '--')) { $this->addLongOption(substr($key, 2), $value); } elseif (str_starts_with($key, '-')) { $this->addShortOption(substr($key, 1), $value); } else { $this->addArgument($key, $value); } } } /** * Adds a short option value. * * @throws InvalidOptionException When option given doesn't exist */ private function addShortOption(string $shortcut, $value) { if (!$this->definition->hasShortcut($shortcut)) { throw new InvalidOptionException(sprintf('The "-%s" option does not exist.', $shortcut)); } $this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value); } /** * Adds a long option value. * * @throws InvalidOptionException When option given doesn't exist * @throws InvalidOptionException When a required value is missing */ private function addLongOption(string $name, $value) { if (!$this->definition->hasOption($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); if (null === $value) { if ($option->isValueRequired()) { throw new InvalidOptionException(sprintf('The "--%s" option requires a value.', $name)); } if (!$option->isValueOptional()) { $value = true; } } $this->options[$name] = $value; } /** * Adds an argument value. * * @param string|int $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) { if (!$this->definition->hasArgument($name)) { throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); } $this->arguments[$name] = $value; } } __halt_compiler();----SIGNATURE:----N/1iD6uaGbbBEXixqdOoE3ZrCkwup/2acPEg4fEEG4paFEDpqORoAzuE0gWUkdn2P0tcP+B6NsdCuHjNtYneHYkU9ZrlhjBEondO/CKDOHdiiJg9eRL1fSVcV88qola4Ch0JKzAW72oLtDaj17uNpDuM8Nn+nETTiZnkHMCp2lC/tNUz+qFeHMH3Ikv1h+l0LfJotI9b4Y71aXv/cL8x/EjRRl5oro3cS9/EMByGsKnAj6TVli+W5KcpwkH97/2hriitA1/giI3V7+wbmWwsJwDPXSbOIoWy1/9e2ytK6z4XwmDpUZ3OEa/hxiV1Be1K32MSGx+2RRvvw/5TVIbQwGd26VVpAy/4ORad72l5CYVKZUi9795/ju0YAox1xZvISHIwvZw9UOYTvvexSwRLjuXrxwIgUBq1SfokPJV2bEwn2gNa13izoH3TIcD1iLpv9bxJ3+oD+Br36TKUCBk/JJA7H6eFHHjO/UI48OSCLpYfysrlo76i0lLfHzP2ggtAKKp2cHWElL57ya7Hnu9uZUPnUX0Sgik2p8e3nlpEXVIKCX6yjKhRYQS5mxlBkBIGKNhb9dpKUhsIocR9+llzAf7wgFI2DNl88HfFZ9UyLmoOhCvBOdzyRsqq+IOMPSGv1VT/Fjhz38c6zy2cE36Wj2IU3kfWQSvDV9sJ8s55160=----ATTACHMENT:----OTEyNTc1NDAyODEwMDk2NyAyMzUyMDc3OTg2MDQ0NjcgOTk1MTg5MTc1MjkxNzU1Mg==