PHP 클래스 Webmozart\Console\Api\Args\Format\Option

Args options are passed after the command name(s). Each option has a long name that is prefixed by two dashes ("--") and optionally a short name that is prefixed by one dash only ("-"). The long name must have at least two characters, the short name must contain a single letter only. In the example below, "--verbose" and "-v" are the long and short names of the same option: $ console server --verbose $ console server -v The long and short names are passed to the constructor of this class. The leading dashes can be omitted: php $option = new Option('verbose', 'v'); If an option accepts a value, you must pass one of the flags {@link VALUE_REQUIRED}, {@link VALUE_OPTIONAL} or {@link MULTI_VALUED} to the constructor: php $option = new Option('format', 'f', Option::VALUE_REQUIRED); * The flag {@link VALUE_REQUIRED} indicates that a value must always be passed. * The flag {@link VALUE_OPTIONAL} indicates that a value may optionally be passed. If no value is passed, the default value passed to the constructor is returned, which defaults to null. * The flag {@link MULTI_VALUED} indicates that the option can be passed multiple times with different values. The passed values are returned to the application as array. The value of a multi-valued option is always required.
부터: 1.0
저자: Bernhard Schussek ([email protected])
상속: extends AbstractOption
파일 보기 프로젝트 열기: webmozart/console 1 사용 예제들

공개 메소드들

메소드 설명
__construct ( string $longName, string | null $shortName = null, integer $flags, string $description = null, mixed $defaultValue = null, string $valueName = '...' ) Creates a new option.
acceptsValue ( ) : boolean Returns whether the option accepts a value.
getDefaultValue ( ) : mixed Returns the default value of the option.
getValueName ( ) : string Returns the name of the option value.
isMultiValued ( ) : boolean Returns whether the option accepts multiple values.
isValueOptional ( ) : boolean Returns whether the option takes an optional value.
isValueRequired ( ) : boolean Returns whether the option requires a value.
parseValue ( mixed $value ) : mixed Parses an option value.
setDefaultValue ( mixed $defaultValue = null ) Sets the default value of the option.

비공개 메소드들

메소드 설명
addDefaultFlags ( &$flags )
assertFlagsValid ( $flags )

메소드 상세

__construct() 공개 메소드

Creates a new option.
public __construct ( string $longName, string | null $shortName = null, integer $flags, string $description = null, mixed $defaultValue = null, string $valueName = '...' )
$longName string The long option name.
$shortName string | null The short option name.
$flags integer A bitwise combination of the option flag constants.
$description string A human-readable description of the option.
$defaultValue mixed The default value (must be null for {@link VALUE_REQUIRED} or {@link VALUE_NONE}).
$valueName string The name of the value to be used in usage examples of the option.

acceptsValue() 공개 메소드

Returns whether the option accepts a value.
public acceptsValue ( ) : boolean
리턴 boolean Returns `true` if a value flag other than {@link VALUE_NONE} was passed to the constructor.

getDefaultValue() 공개 메소드

Returns the default value of the option.
public getDefaultValue ( ) : mixed
리턴 mixed The default value.

getValueName() 공개 메소드

This name can be used as placeholder of the value when displaying the option's usage.
public getValueName ( ) : string
리턴 string The name of the option value.

isMultiValued() 공개 메소드

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

isValueOptional() 공개 메소드

Returns whether the option takes an optional value.
public isValueOptional ( ) : boolean
리턴 boolean Returns `true` if the flag {@link VALUE_OPTIONAL} was passed to the constructor.

isValueRequired() 공개 메소드

Returns whether the option requires a value.
public isValueRequired ( ) : boolean
리턴 boolean Returns `true` if the flag {@link VALUE_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 option does not accept a value, 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.