ConsoleInputOption
in package
An object to represent a single option used in the command line.
ConsoleOptionParser creates these when you use addOption()
Tags
Table of Contents
Properties
- $_boolean : bool
- Is the option a boolean option. Boolean options do not consume a parameter.
- $_choices : array<string|int, string>
- An array of choices for the option.
- $_default : string|bool|null
- Default value for the option
- $_help : string
- Help text for the option.
- $_multiple : bool
- Can the option accept multiple value definition.
- $_name : string
- Name of the option
- $_short : string
- Short (1 character) alias for the option.
- $prompt : string|null
- The prompt string
- $required : bool
- Is the option required.
Methods
- __construct() : mixed
- Make a new Input Option
- acceptsMultiple() : bool
- Check if this option accepts multiple values.
- choices() : array<string|int, mixed>
- Get the list of choices this option has.
- defaultValue() : string|bool|null
- Get the default value for this option
- help() : string
- Generate the help for this this option.
- isBoolean() : bool
- Check if this option is a boolean option
- isRequired() : bool
- Check if this option is required
- name() : string
- Get the value of the name attribute.
- prompt() : string
- Get the prompt string
- short() : string
- Get the value of the short attribute.
- usage() : string
- Get the usage value for this option
- validChoice() : true
- Check that a value is a valid choice for this option.
- xml() : SimpleXMLElement
- Append the option's XML into the parent.
Properties
$_boolean
Is the option a boolean option. Boolean options do not consume a parameter.
protected
bool
$_boolean
$_choices
An array of choices for the option.
protected
array<string|int, string>
$_choices
$_default
Default value for the option
protected
string|bool|null
$_default
$_help
Help text for the option.
protected
string
$_help
$_multiple
Can the option accept multiple value definition.
protected
bool
$_multiple
$_name
Name of the option
protected
string
$_name
$_short
Short (1 character) alias for the option.
protected
string
$_short
$prompt
The prompt string
protected
string|null
$prompt
$required
Is the option required.
protected
bool
$required
Methods
__construct()
Make a new Input Option
public
__construct(string $name[, string $short = '' ][, string $help = '' ][, bool $isBoolean = false ][, string|bool|null $default = null ][, array<string|int, string> $choices = [] ][, bool $multiple = false ][, bool $required = false ][, string|null $prompt = null ]) : mixed
Parameters
- $name : string
-
The long name of the option, or an array with all the properties.
- $short : string = ''
-
The short alias for this option
- $help : string = ''
-
The help text for this option
- $isBoolean : bool = false
-
Whether this option is a boolean option. Boolean options don't consume extra tokens
- $default : string|bool|null = null
-
The default value for this option.
- $choices : array<string|int, string> = []
-
Valid choices for this option.
- $multiple : bool = false
-
Whether this option can accept multiple value definition.
- $required : bool = false
-
Whether this option is required or not.
- $prompt : string|null = null
-
The prompt string.
Tags
acceptsMultiple()
Check if this option accepts multiple values.
public
acceptsMultiple() : bool
Return values
boolchoices()
Get the list of choices this option has.
public
choices() : array<string|int, mixed>
Return values
array<string|int, mixed>defaultValue()
Get the default value for this option
public
defaultValue() : string|bool|null
Return values
string|bool|nullhelp()
Generate the help for this this option.
public
help([int $width = 0 ]) : string
Parameters
- $width : int = 0
-
The width to make the name of the option.
Return values
stringisBoolean()
Check if this option is a boolean option
public
isBoolean() : bool
Return values
boolisRequired()
Check if this option is required
public
isRequired() : bool
Return values
boolname()
Get the value of the name attribute.
public
name() : string
Return values
string —Value of this->_name.
prompt()
Get the prompt string
public
prompt() : string
Return values
stringshort()
Get the value of the short attribute.
public
short() : string
Return values
string —Value of this->_short.
usage()
Get the usage value for this option
public
usage() : string
Return values
stringvalidChoice()
Check that a value is a valid choice for this option.
public
validChoice(string|bool $value) : true
Parameters
- $value : string|bool
-
The choice to validate.
Tags
Return values
truexml()
Append the option's XML into the parent.
public
xml(SimpleXMLElement $parent) : SimpleXMLElement
Parameters
- $parent : SimpleXMLElement
-
The parent element.
Return values
SimpleXMLElement —The parent with this option appended.