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

hasOption() public méthode

You can either pass the long or the short name of the option.
public hasOption ( string $name, boolean $includeBase = true ) : boolean
$name string The long or short option name.
$includeBase boolean Whether to include options in the base format in the search.
Résultat boolean Returns `true` if the option with the given name could be found and `false` otherwise.
    public function hasOption($name, $includeBase = true)
    {
        Assert::string($name, 'The option name must be a string or an integer. Got: %s');
        Assert::notEmpty($name, 'The option name must not be empty.');
        Assert::boolean($includeBase, 'The parameter $includeBase must be a boolean. Got: %s');
        if (isset($this->options[$name]) || isset($this->optionsByShortName[$name])) {
            return true;
        }
        if ($includeBase && $this->baseFormat) {
            return $this->baseFormat->hasOption($name);
        }
        return false;
    }

Usage Example

 /**
  * {@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::hasOption