PHP Класс Webmozart\Console\Api\Args\Args

The parsed arguments provide access to the options and arguments passed via the command line. Usually you can construct an {@link Args} instance by parsing a {@link RawArgs} instance with an {@link ArgsParser}: php $format = ArgsFormat::build() ->addCommandName(new CommandName('server')) ->addCommandName(new CommandName('add')) ->addOption(new Option('port', 'p', Option::VALUE_REQUIRED | Option::INTEGER)) ->addArgument(new Argument('host', Argument::REQUIRED)) ->getFormat(); $args = $parser->parseArgs($rawArgs, $format); The {@link ArgsFormat} defines which rules the console arguments must adhere to. You can also create {@link Args} instances manually. This is especially useful in tests: php $format = ArgsFormat::build() ->addOption(new Option('port', 'p', Option::VALUE_REQUIRED | Option::INTEGER)) ->addArgument(new Argument('host', Argument::REQUIRED)) ->getFormat(); $args = new Args($format); $args->setOption('port', 80); $args->setArgument('host', 'localhost');
С версии: 1.0
Автор: Bernhard Schussek ([email protected])
Показать файл Открыть проект Примеры использования класса

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

Метод Описание
__construct ( ArgsFormat $format, Webmozart\Console\Api\Args\RawArgs $rawArgs = null ) Creates the console arguments.
addArguments ( array $arguments ) : static Sets the values of multiple arguments.
addOptions ( array $options ) : static Sets the values of multiple options.
getArgument ( string | integer $name ) : mixed Returns the value of an argument.
getArguments ( boolean $includeDefaults = true ) : array Returns the values of all arguments.
getCommandNames ( ) : CommandName[] Returns the command names as array.
getCommandOptions ( ) : CommandOption[] Returns the command options as array.
getFormat ( ) : ArgsFormat Returns the format of the console arguments.
getOption ( string $name ) : mixed Returns an option.
getOptions ( boolean $includeDefaults = true ) : array Returns all options.
getRawArgs ( ) : Webmozart\Console\Api\Args\RawArgs Returns the raw console arguments.
getScriptName ( ) : string | null Returns the PHP script as it was called on the console.
isArgumentDefined ( string | integer $name ) : boolean Returns whether an argument is defined in the format.
isArgumentSet ( string | integer $name ) : boolean Returns whether an argument is set.
isOptionDefined ( string $name ) : boolean Returns whether an option is defined in the format.
isOptionSet ( string $name ) : boolean Returns whether an option is set.
setArgument ( string | integer $name, mixed $value ) : static Sets the value of an argument.
setArguments ( array $arguments ) : static Sets the values of multiple arguments.
setOption ( string $name, mixed $value = true ) : static Sets an option.
setOptions ( array $options ) : static Sets the values of multiple options.

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

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

Creates the console arguments.
public __construct ( ArgsFormat $format, Webmozart\Console\Api\Args\RawArgs $rawArgs = null )
$format Webmozart\Console\Api\Args\Format\ArgsFormat The format that the arguments and options must adhere to.
$rawArgs Webmozart\Console\Api\Args\RawArgs The raw console arguments.

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

The existing arguments are preserved.
См. также: setArgument()
public addArguments ( array $arguments ) : static
$arguments array The argument values indexed by the argument names or their 0-based positions in the argument list.
Результат static The current instance.

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

The existing options are preserved.
См. также: setOption()
public addOptions ( array $options ) : static
$options array The options indexed by their long or short names and their values.
Результат static The current instance.

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

If the argument is not set, the default value configured in the argument format is returned.
public getArgument ( string | integer $name ) : mixed
$name string | integer The argument name or its 0-based position in the argument list.
Результат mixed The value of the argument.

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

By default, this method also includes the default values of unset arguments. You can disable this behavior by passing false for $includeDefaults.
См. также: getArgument()
public getArguments ( boolean $includeDefaults = true ) : array
$includeDefaults boolean Whether to return the default values for arguments that were not set.
Результат array The argument values.

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

Returns the command names as array.
public getCommandNames ( ) : CommandName[]
Результат Webmozart\Console\Api\Args\Format\CommandName[] The command names.

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

Returns the command options as array.
public getCommandOptions ( ) : CommandOption[]
Результат Webmozart\Console\Api\Args\Format\CommandOption[] The command options.

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

Returns the format of the console arguments.
public getFormat ( ) : ArgsFormat
Результат Webmozart\Console\Api\Args\Format\ArgsFormat The format.

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

If the option accepts a value, the value set for that option is returned. If no value was set with {@link setOption()}, the default value of the option is returned.j If the option accepts no value, the method returns true if the option was set and false otherwise.
public getOption ( string $name ) : mixed
$name string The long or short option name.
Результат mixed The option value or `true`/`false` for options without values.

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

By default, this method also includes the default values set for options with values. You can disable this behavior by passing false for $includeDefaults.
См. также: getOption()
public getOptions ( boolean $includeDefaults = true ) : array
$includeDefaults boolean Whether to return the default values for options that were not set.
Результат array The option values and `true`/`false` for options without values.

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

Returns the raw console arguments.
public getRawArgs ( ) : Webmozart\Console\Api\Args\RawArgs
Результат Webmozart\Console\Api\Args\RawArgs The raw arguments.

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

Returns the PHP script as it was called on the console.
public getScriptName ( ) : string | null
Результат string | null The script name or null if no script name is available.

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

Returns whether an argument is defined in the format.
public isArgumentDefined ( string | integer $name ) : boolean
$name string | integer The argument name or its 0-based position in the argument list.
Результат boolean Returns `true` if the argument exists and `false` otherwise.

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

Returns whether an argument is set.
public isArgumentSet ( string | integer $name ) : boolean
$name string | integer The argument name or its 0-based position in the argument list.
Результат boolean Returns `true` if the argument is set and `false` otherwise.

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

Returns whether an option is defined in the format.
public isOptionDefined ( string $name ) : boolean
$name string The long or short option name.
Результат boolean Returns `true` if the option exists and `false` otherwise.

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

Returns whether an option is set.
public isOptionSet ( string $name ) : boolean
$name string The long or short option name.
Результат boolean Returns `true` if the option is set and `false` otherwise.

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

The value is converted to the type defined by the argument format.
public setArgument ( string | integer $name, mixed $value ) : static
$name string | integer The argument name or its 0-based position in the argument list.
$value mixed The value of the argument.
Результат static The current instance.

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

The existing arguments are unset.
См. также: setArgument()
public setArguments ( array $arguments ) : static
$arguments array The argument values indexed by the argument names or their 0-based positions in the argument list.
Результат static The current instance.

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

For options with values, you can pass the value in the second argument. The value is converted to the type defined by the argument format. For options without values, you can omit the second argument. Optionally, you can pass true/false explicitly to enable/disable the option.
public setOption ( string $name, mixed $value = true ) : static
$name string The long or short option name.
$value mixed The value to set for the option.
Результат static The current instance.

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

The existing options are unset.
См. также: setOption()
public setOptions ( array $options ) : static
$options array The options indexed by their long or short names and their values.
Результат static The current instance.