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.
С версии: 1.0
Автор: Bernhard Schussek ([email protected])
Наследование: extends AbstractOption
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__construct ( string $longName, string | null $shortName = null, integer $flags, string $description = null, mixed $defaultValue = null, string $valueName = '...' ) Creates a new option.
acceptsValue ( ) : boolean Returns whether the option accepts a value.
getDefaultValue ( ) : mixed Returns the default value of the option.
getValueName ( ) : string Returns the name of the option value.
isMultiValued ( ) : boolean Returns whether the option accepts multiple values.
isValueOptional ( ) : boolean Returns whether the option takes an optional value.
isValueRequired ( ) : boolean Returns whether the option requires a value.
parseValue ( mixed $value ) : mixed Parses an option value.
setDefaultValue ( mixed $defaultValue = null ) Sets the default value of the option.

Приватные методы

Метод Описание
addDefaultFlags ( &$flags )
assertFlagsValid ( $flags )

Описание методов

__construct() публичный Метод

Creates a new option.
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.
public getDefaultValue ( ) : mixed
Результат mixed The default value.

getValueName() публичный Метод

This name can be used as placeholder of the value when displaying the option's usage.
public getValueName ( ) : string
Результат string The name of the option value.

isMultiValued() публичный Метод

Returns whether the option accepts multiple values.
public isMultiValued ( ) : boolean
Результат boolean Returns `true` if the flag {@link MULTI_VALUED} was passed to the constructor.

isValueOptional() публичный Метод

Returns whether the option takes an optional value.
public isValueOptional ( ) : boolean
Результат boolean Returns `true` if the flag {@link VALUE_OPTIONAL} was passed to the constructor.

isValueRequired() публичный Метод

Returns whether the option requires a value.
public isValueRequired ( ) : boolean
Результат boolean Returns `true` if the flag {@link VALUE_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.
public parseValue ( mixed $value ) : mixed
$value mixed The value to parse.
Результат mixed The parsed value.

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.
public setDefaultValue ( mixed $defaultValue = null )
$defaultValue mixed The default value.