Webmozart\Console\Api\Args\Format\ArgsFormat::getArgument PHP Méthode

getArgument() public méthode

You can either pass the name of the argument or the 0-based position of the argument.
public getArgument ( string | integer $name, boolean $includeBase = true ) : Argument
$name string | integer The argument name or its 0-based position in the argument list.
$includeBase boolean Whether to include arguments in the base format in the search.
Résultat Argument The argument.
    public function getArgument($name, $includeBase = true)
    {
        if (!is_int($name)) {
            Assert::string($name, 'The argument name must be a string or an integer. Got: %s');
            Assert::notEmpty($name, 'The argument name must not be empty.');
        }
        Assert::boolean($includeBase, 'The parameter $includeBase must be a boolean. Got: %s');
        if (is_int($name)) {
            $arguments = array_values($this->getArguments($includeBase));
            if (!isset($arguments[$name])) {
                throw NoSuchArgumentException::forPosition($name);
            }
        } else {
            $arguments = $this->getArguments($includeBase);
            if (!isset($arguments[$name])) {
                throw NoSuchArgumentException::forArgumentName($name);
            }
        }
        return $arguments[$name];
    }

Usage Example

Exemple #1
0
 /**
  * Sets the value of an argument.
  *
  * The value is converted to the type defined by the argument format.
  *
  * @param string|int $name  The argument name or its 0-based position in the
  *                          argument list.
  * @param mixed      $value The value of the argument.
  *
  * @return static The current instance.
  *
  * @throws NoSuchArgumentException If the argument does not exist.
  */
 public function setArgument($name, $value)
 {
     $argument = $this->format->getArgument($name);
     if ($argument->isMultiValued()) {
         $value = (array) $value;
         foreach ($value as $k => $v) {
             $value[$k] = $argument->parseValue($v);
         }
     } else {
         $value = $argument->parseValue($value);
     }
     $this->arguments[$argument->getName()] = $value;
     return $this;
 }
All Usage Examples Of Webmozart\Console\Api\Args\Format\ArgsFormat::getArgument