PHP Class kahlan\cli\CommandLine

Show file Open project: crysalead/kahlan Class Usage Examples

Protected Properties

Property Type Description
$_defaults array Defaults options values
$_options array Arguments attributes
$_values array Arguments values.

Public Methods

Method Description
__construct ( array $options = [] ) The Constructor.
add ( string $name, mixed $value ) : array Adds a value to a specific option (or set if it's not an array).
cast ( string $value, string $type, boolean $array = false ) : array Casts a value according to the option attributes.
exists ( string $name ) : boolean Checks if an option has been setted.
get ( string $name = null ) : array Gets the value of a specific option.
option ( string $name = null, array $config = [], $value = null ) : array Gets/Sets/Overrides an option's attributes.
options ( ) : array Returns all options attributes.
parse ( array $argv, boolean $override = true ) : array Parses a command line argv.
set ( string $name, mixed $value ) : array Sets the value of a specific option.

Protected Methods

Method Description
_get ( string $name ) : array Helper for get().
_parse ( string $arg ) : array Helper for parse().
_splitOptionName ( string $name ) : array Helper to split option name

Method Details

__construct() public method

The Constructor.
public __construct ( array $options = [] )
$options array An array of option's attributes where keys are option's names and values are an array of attributes.

_get() protected method

Helper for get().
protected _get ( string $name ) : array
$name string The name of the option.
return array The casted value.

_parse() protected method

Helper for parse().
protected _parse ( string $arg ) : array
$arg string A string argument.
return array The parsed argument

_splitOptionName() protected method

Helper to split option name
protected _splitOptionName ( string $name ) : array
$name string The option name.
return array

add() public method

Adds a value to a specific option (or set if it's not an array).
public add ( string $name, mixed $value ) : array
$name string The name of the option.
$value mixed The value of the option to set.
return array The setted value.

cast() public method

Casts a value according to the option attributes.
public cast ( string $value, string $type, boolean $array = false ) : array
$value string The value to cast.
$type string The type of the value.
$array boolean If `true`, the argument value is considered to be an array.
return array The casted value.

exists() public method

Checks if an option has been setted.
public exists ( string $name ) : boolean
$name string The name of the option.
return boolean

get() public method

Gets the value of a specific option.
public get ( string $name = null ) : array
$name string The name of the option.
return array The value.

option() public method

Gets/Sets/Overrides an option's attributes.
public option ( string $name = null, array $config = [], $value = null ) : array
$name string The name of the option.
$config array The option attributes to set.
return array

options() public method

Returns all options attributes.
public options ( ) : array
return array

parse() public method

Parses a command line argv.
public parse ( array $argv, boolean $override = true ) : array
$argv array An argv data.
$override boolean If set to `false` it doesn't override already setted data.
return array The parsed attributes

set() public method

Sets the value of a specific option.
public set ( string $name, mixed $value ) : array
$name string The name of the option.
$value mixed The value of the option to set.
return array The setted value.

Property Details

$_defaults protected property

Defaults options values
protected array $_defaults
return array

$_options protected property

Arguments attributes
protected array $_options
return array

$_values protected property

Arguments values.
protected array $_values
return array