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);
Afficher le fichier
Open project: webmozart/console
Class Usage Examples
Méthodes publiques
Private Methods
Method Details
__construct()
public méthode
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 méthode
Returns the default value of the argument.
getDescription()
public méthode
Returns the description text.
Returns the name of the argument.
isMultiValued()
public méthode
Returns whether the argument accepts multiple values.
isOptional()
public méthode
Returns whether the argument is optional.
public isOptional ( ) : boolean |
Résultat |
boolean |
Returns `true` if the flag {@link OPTIONAL} was passed to
the constructor. |
isRequired()
public méthode
Returns whether the argument is required.
public isRequired ( ) : boolean |
Résultat |
boolean |
Returns `true` if the flag {@link REQUIRED} was passed to
the constructor. |
parseValue()
public méthode
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()
public méthode
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.