PHP Класс Webmozart\Console\Api\Args\Format\Argument
Args arguments are passed after the command name and its options. In the
example below, "localhost" is the argument to the "server -d" command.
$ console server -d localhost
Arguments can be either optional or required. By default, all arguments are
optional, but you can explicitly make an argument optional or required by
passing one of the flags {@link OPTIONAL} and {@link REQUIRED} to the
constructor:
php
$argument = new Argument('server', Argument::REQUIRED);
Arguments can also be multi-valued. Multi-valued arguments can be passed any
number of times:
$ console server -d localhost google.com
To create a multi-valued argument, pass the flag {@link MULTI_VALUED} to the
constructor:
php
$argument = new Argument('server', Argument::MULTI_VALUED);
You can combine the {@link MULTI_VALUED} flag with either {@link OPTIONAL}
or {@link REQUIRED} using the bitwise operator "|":
php
$argument = new Argument('server', Argument::REQUIRED | Argument::MULTI_VALUED);
Показать файл
Открыть проект
Примеры использования класса
Открытые методы
Приватные методы
Описание методов
__construct()
публичный Метод
public __construct ( string $name, integer $flags, string $description = null, mixed $defaultValue = null ) |
$name |
string |
The argument name |
$flags |
integer |
A bitwise combination of the flag constants. |
$description |
string |
A human-readable description of the argument. |
$defaultValue |
mixed |
The default value of the argument (must be
null for the flag {@link self::REQUIRED}). |
getDefaultValue()
публичный Метод
Returns the default value of the argument.
getDescription()
публичный Метод
Returns the description text.
getName()
публичный Метод
Returns the name of the argument.
isMultiValued()
публичный Метод
Returns whether the argument accepts multiple values.
isOptional()
публичный Метод
Returns whether the argument is optional.
public isOptional ( ) : boolean |
Результат |
boolean |
Returns `true` if the flag {@link OPTIONAL} was passed to
the constructor. |
isRequired()
публичный Метод
Returns whether the argument is required.
public isRequired ( ) : boolean |
Результат |
boolean |
Returns `true` if the flag {@link REQUIRED} was passed to
the constructor. |
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 argument is required, this method throws an exception.
If the option is multi-valued, the passed value must be an array or
null.