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

getCommandOption() public méthode

Returns a command option by its long or short name.
public getCommandOption ( string $name, boolean $includeBase = true ) : CommandOption
$name string The long or short option name.
$includeBase boolean Whether to include options in the base format in the search.
Résultat CommandOption The command option.
    public function getCommandOption($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->commandOptions[$name])) {
            return $this->commandOptions[$name];
        }
        if (isset($this->commandOptionsByShortName[$name])) {
            return $this->commandOptionsByShortName[$name];
        }
        if ($includeBase && $this->baseFormat) {
            return $this->baseFormat->getCommandOption($name);
        }
        throw NoSuchOptionException::forOptionName($name);
    }

Usage Example

 /**
  * Returns a command option by its long or short name.
  *
  * @param string $name        The long or short option name.
  * @param bool   $includeBase Whether to include command options in the base
  *                            format in the search.
  *
  * @return CommandOption The command option.
  *
  * @throws NoSuchOptionException If the command  option with the given name
  *                               does not not exist.
  */
 public function getCommandOption($name, $includeBase = true)
 {
     Assert::string($name, 'The option name must be a string. 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->commandOptions[$name])) {
         return $this->commandOptions[$name];
     }
     if (isset($this->commandOptionsByShortName[$name])) {
         return $this->commandOptionsByShortName[$name];
     }
     if ($includeBase && $this->baseFormat) {
         return $this->baseFormat->getCommandOption($name);
     }
     throw NoSuchOptionException::forOptionName($name);
 }
All Usage Examples Of Webmozart\Console\Api\Args\Format\ArgsFormat::getCommandOption