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])
파일 보기 프로젝트 열기: webmozart/console 1 사용 예제들

공개 메소드들

메소드 설명
__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.