Fr3nch13/CakePHP Utilities

ConsoleInputOption
in package

An object to represent a single option used in the command line.

ConsoleOptionParser creates these when you use addOption()

Tags
see
ConsoleOptionParser::addOption()

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

$_multiple

Can the option accept multiple value definition.

protected bool $_multiple

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
throws
ConsoleException

acceptsMultiple()

Check if this option accepts multiple values.

public acceptsMultiple() : bool
Return values
bool

choices()

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|null

help()

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
string

isBoolean()

Check if this option is a boolean option

public isBoolean() : bool
Return values
bool

isRequired()

Check if this option is required

public isRequired() : bool
Return values
bool

name()

Get the value of the name attribute.

public name() : string
Return values
string

Value of this->_name.

short()

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
string

validChoice()

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
throws
ConsoleException
Return values
true

xml()

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.


        
On this page

Search results