Documentation

InputOption
in package

Represents a command line option.

Tags
author

Fabien Potencier fabien@symfony.com

Table of Contents

VALUE_IS_ARRAY  = 8
The option accepts multiple values (e.g. --dir=/foo --dir=/bar).
VALUE_NEGATABLE  = 16
The option may have either positive or negative value (e.g. --ansi or --no-ansi).
VALUE_NONE  = 1
Do not accept input for the option (e.g. --yell). This is the default behavior of options.
VALUE_OPTIONAL  = 4
The option may or may not have a value (e.g. --yell or --yell=loud).
VALUE_REQUIRED  = 2
A value must be passed when the option is used (e.g. --iterations=5 or -i5).
$default  : mixed
$description  : mixed
$mode  : mixed
$name  : mixed
$shortcut  : mixed
__construct()  : mixed
acceptValue()  : bool
Returns true if the option accepts a value.
equals()  : bool
Checks whether the given option equals this one.
getDefault()  : string|array<string|int, string>|bool|null
Returns the default value.
getDescription()  : string
Returns the description text.
getName()  : string
Returns the option name.
getShortcut()  : string|null
Returns the option shortcut.
isArray()  : bool
Returns true if the option can take multiple values.
isNegatable()  : bool
isValueOptional()  : bool
Returns true if the option takes an optional value.
isValueRequired()  : bool
Returns true if the option requires a value.
setDefault()  : mixed
Sets the default value.

Constants

VALUE_IS_ARRAY

The option accepts multiple values (e.g. --dir=/foo --dir=/bar).

public mixed VALUE_IS_ARRAY = 8

VALUE_NEGATABLE

The option may have either positive or negative value (e.g. --ansi or --no-ansi).

public mixed VALUE_NEGATABLE = 16

VALUE_NONE

Do not accept input for the option (e.g. --yell). This is the default behavior of options.

public mixed VALUE_NONE = 1

VALUE_OPTIONAL

The option may or may not have a value (e.g. --yell or --yell=loud).

public mixed VALUE_OPTIONAL = 4

VALUE_REQUIRED

A value must be passed when the option is used (e.g. --iterations=5 or -i5).

public mixed VALUE_REQUIRED = 2

Properties

Methods

__construct()

public __construct(string $name[, string|array<string|int, mixed>|null $shortcut = null ][, int|null $mode = null ][, string $description = '' ][, string|array<string|int, string>|bool|null $default = null ]) : mixed
Parameters
$name : string

The option name

$shortcut : string|array<string|int, mixed>|null = null

The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts

$mode : int|null = null

The option mode: One of the VALUE_* constants

$description : string = ''

A description text

$default : string|array<string|int, string>|bool|null = null

The default value (must be null for self::VALUE_NONE)

Tags
throws
InvalidArgumentException

If option mode is invalid or incompatible

Return values
mixed

acceptValue()

Returns true if the option accepts a value.

public acceptValue() : bool
Return values
bool

true if value mode is not self::VALUE_NONE, false otherwise

equals()

Checks whether the given option equals this one.

public equals(self $option) : bool
Parameters
$option : self
Return values
bool

getDefault()

Returns the default value.

public getDefault() : string|array<string|int, string>|bool|null
Return values
string|array<string|int, string>|bool|null

The default value

getDescription()

Returns the description text.

public getDescription() : string
Return values
string

The description text

getName()

Returns the option name.

public getName() : string
Return values
string

The name

getShortcut()

Returns the option shortcut.

public getShortcut() : string|null
Return values
string|null

The shortcut

isArray()

Returns true if the option can take multiple values.

public isArray() : bool
Return values
bool

true if mode is self::VALUE_IS_ARRAY, false otherwise

isNegatable()

public isNegatable() : bool
Return values
bool

isValueOptional()

Returns true if the option takes an optional value.

public isValueOptional() : bool
Return values
bool

true if value mode is self::VALUE_OPTIONAL, false otherwise

isValueRequired()

Returns true if the option requires a value.

public isValueRequired() : bool
Return values
bool

true if value mode is self::VALUE_REQUIRED, false otherwise

setDefault()

Sets the default value.

public setDefault([string|array<string|int, string>|bool|null $default = null ]) : mixed
Parameters
$default : string|array<string|int, string>|bool|null = null

The default value

Tags
throws
LogicException

When incorrect default value is given

Return values
mixed

Search results