Webmozart\Console\Api\Args\Format\ArgsFormat::hasArgument PHP Method

hasArgument() public method

You can either pass the name of the argument or the 0-based position of the argument.
public hasArgument ( string | integer $name, boolean $includeBase = true ) : boolean
$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.
return boolean Returns `true` if the argument with the given name or position could be found and `false` otherwise.
    public function hasArgument($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');
        $arguments = is_int($name) ? array_values($this->getArguments($includeBase)) : $this->getArguments($includeBase);
        return isset($arguments[$name]);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getCommandFrom($className)
 {
     if (class_exists($className)) {
         $accessor = PropertyAccess::createPropertyAccessor();
         $reflector = new \ReflectionClass($className);
         $instance = $reflector->newInstanceWithoutConstructor();
         foreach ($reflector->getProperties() as $property) {
             if ($instance instanceof ConsoleCommandInterface && $property->getName() == 'io') {
                 continue;
             }
             if (!$this->format->hasArgument($property->getName()) && !$this->format->hasOption($property->getName())) {
                 throw new \InvalidArgumentException(sprintf("There is not '%s' argument defined in the %s command", $property->getName(), $className));
             }
             $value = null;
             if ($this->format->hasArgument($property->getName())) {
                 $value = $this->args->getArgument($property->getName());
             } elseif ($this->format->hasOption($property->getName())) {
                 $value = $this->args->getOption($property->getName());
             }
             $accessor->setValue($instance, $property->getName(), $value);
         }
         return $instance;
     }
     return;
 }
All Usage Examples Of Webmozart\Console\Api\Args\Format\ArgsFormat::hasArgument