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

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

Метод Описание
__construct ( string $name, integer $flags, string $description = null, mixed $defaultValue = null ) Creates a new argument.
getDefaultValue ( ) : mixed Returns the default value of the argument.
getDescription ( ) : string Returns the description text.
getName ( ) : string Returns the name of the argument.
isMultiValued ( ) : boolean Returns whether the argument accepts multiple values.
isOptional ( ) : boolean Returns whether the argument is optional.
isRequired ( ) : boolean Returns whether the argument is required.
parseValue ( mixed $value ) : mixed Parses an argument value.
setDefaultValue ( mixed $defaultValue = null ) Sets the default value.

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

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

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

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

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

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

Returns the description text.
public getDescription ( ) : string
Результат string The description text.

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

Returns the name of the argument.
public getName ( ) : string
Результат string The argument name.

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

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

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.
public parseValue ( mixed $value ) : mixed
$value mixed The value to parse.
Результат mixed The parsed value.

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