PHP Класс Webmozart\Console\Api\Args\Format\Option
Args options are passed after the command name(s). Each option has a
long name that is prefixed by two dashes ("--") and optionally a short name
that is prefixed by one dash only ("-"). The long name must have at least
two characters, the short name must contain a single letter only.
In the example below, "--verbose" and "-v" are the long and short names of
the same option:
$ console server --verbose
$ console server -v
The long and short names are passed to the constructor of this class. The
leading dashes can be omitted:
php
$option = new Option('verbose', 'v');
If an option accepts a value, you must pass one of the flags
{@link VALUE_REQUIRED}, {@link VALUE_OPTIONAL} or {@link MULTI_VALUED} to
the constructor:
php
$option = new Option('format', 'f', Option::VALUE_REQUIRED);
* The flag {@link VALUE_REQUIRED} indicates that a value must always be
passed.
* The flag {@link VALUE_OPTIONAL} indicates that a value may optionally be
passed. If no value is passed, the default value passed to the constructor
is returned, which defaults to
null.
* The flag {@link MULTI_VALUED} indicates that the option can be passed
multiple times with different values. The passed values are returned to
the application as array. The value of a multi-valued option is always
required.
Показать файл
Открыть проект
Примеры использования класса
Открытые методы
Приватные методы
Описание методов
__construct()
публичный Метод
public __construct ( string $longName, string | null $shortName = null, integer $flags, string $description = null, mixed $defaultValue = null, string $valueName = '...' ) |
$longName |
string |
The long option name. |
$shortName |
string | null |
The short option name. |
$flags |
integer |
A bitwise combination of the option flag
constants. |
$description |
string |
A human-readable description of the option. |
$defaultValue |
mixed |
The default value (must be null for
{@link VALUE_REQUIRED} or
{@link VALUE_NONE}). |
$valueName |
string |
The name of the value to be used in
usage examples of the option. |
acceptsValue()
публичный Метод
Returns whether the option accepts a value.
public acceptsValue ( ) : boolean |
Результат |
boolean |
Returns `true` if a value flag other than {@link VALUE_NONE}
was passed to the constructor. |
getDefaultValue()
публичный Метод
Returns the default value of the option.
getValueName()
публичный Метод
This name can be used as placeholder of the value when displaying the
option's usage.
isMultiValued()
публичный Метод
Returns whether the option accepts multiple values.
isValueOptional()
публичный Метод
Returns whether the option takes an optional value.
isValueRequired()
публичный Метод
Returns whether the option requires a value.
parseValue()
публичный Метод
Pass one of the flags {@link STRING}, {@link BOOLEAN}, {@link INTEGER}
and {@link FLOAT} to the constructor to configure the result of this
method. You can optionally combine the flags with {@link NULLABLE} to
support the conversion of "null" to null.
setDefaultValue()
публичный Метод
If the option does not accept a value, this method throws an exception.
If the option is multi-valued, the passed value must be an array or
null.