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.
파일 보기
프로젝트 열기: webmozart/console
1 사용 예제들
공개 메소드들
비공개 메소드들
메소드 상세
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. |
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. |
Returns the default value of the option.
This name can be used as placeholder of the value when displaying the
option's usage.
Returns whether the option accepts multiple values.
Returns whether the option takes an optional value.
Returns whether the option requires a value.
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.
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.