PHP Class 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);
Since: 1.0
Author: Bernhard Schussek ([email protected])
Show file Open project: webmozart/console Class Usage Examples

Public Methods

Method Description
__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.

Private Methods

Method Description
addDefaultFlags ( &$flags )
assertFlagsValid ( $flags )

Method Details

__construct() public method

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() public method

Returns the default value of the argument.
public getDefaultValue ( ) : mixed
return mixed The default value.

getDescription() public method

Returns the description text.
public getDescription ( ) : string
return string The description text.

getName() public method

Returns the name of the argument.
public getName ( ) : string
return string The argument name.

isMultiValued() public method

Returns whether the argument accepts multiple values.
public isMultiValued ( ) : boolean
return boolean Returns `true` if the flag {@link MULTI_VALUED} was passed to the constructor.

isOptional() public method

Returns whether the argument is optional.
public isOptional ( ) : boolean
return boolean Returns `true` if the flag {@link OPTIONAL} was passed to the constructor.

isRequired() public method

Returns whether the argument is required.
public isRequired ( ) : boolean
return boolean Returns `true` if the flag {@link REQUIRED} was passed to the constructor.

parseValue() public method

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.
return mixed The parsed value.

setDefaultValue() public method

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.