PHP Class Commando\Command

This is merely for intellisense purposes!
Inheritance: implements ArrayAccess, implements Iterator
Show file Open project: nategood/commando Class Usage Examples

Public Properties

Property Type Description
$methods Valid "option" options, mapped to their aliases

Public Methods

Method Description
__call ( string $name, array $arguments ) : Command This is the meat of Command. Any time we are operating on an individual option for command (e.g. $cmd->option()->require().
__construct ( array | null $tokens = null )
__destruct ( )
__toString ( ) : string
beepOnError ( boolean $beep = true ) : Command Terminal beep on error
current ( ) : mixed
define ( array $tokens = null ) : Command Factory style reads a little nicer
doNotTrapErrors ( ) : Command
error ( Exception $e )
getArgumentValues ( ) : array
getArguments ( ) : array
getFlagValues ( ) : array
getFlags ( ) : array
getHelp ( ) : string
getOption ( string $option ) : Option
getOptions ( ) : array
getSize ( ) : integer
hasOption ( string $option ) : boolean
isParsed ( ) : boolean Has this Command instance parsed its arguments?
key ( ) : integer
next ( )
offsetExists ( string $offset ) : boolean
offsetGet ( string $offset ) : mixed
offsetSet ( string $offset, string $value )
offsetUnset ( string $offset )
parse ( ) : void
printHelp ( )
rewind ( )
setHelp ( string $help ) : Command
setTokens ( array $cli_tokens ) : Command Rare that you would need to use this other than for testing, allows defining the cli tokens, instead of using $argv
trapErrors ( boolean $trap = true ) : Command
useDefaultHelp ( boolean $help = true )
valid ( ) : boolean

Private Methods

Method Description
_alias ( Option $option, string $alias ) : Option
_argument ( Option | null $option, integer $index = null ) : Option
_boolean ( Option $option, boolean $boolean = true ) : Option
_default ( Option $option, mixed $value ) : Option
_describe ( Option $option, string $description ) : Option
_file ( Option $option, boolean $require_exists = true, boolean $allow_globbing = false ) : void
_flag ( Option | null $option, string $name ) : Option
_increment ( Option $option, integer $max ) : Option
_map ( Option $option, Closure $callback ) : Option
_must ( Option $option, Closure $callback ) : Option
_needs ( Option $option, string $name ) : Option Set a requirement on an option
_option ( Option | null $option, string | integer $name = null ) : Option
_parseOption ( string $token ) : array
_require ( Option $option, boolean $require = true ) : Option
_title ( Option $option, string $title ) : Option
attachHelp ( )
dedupeFlags ( ) : array
parseIfNotParsed ( ) : void

Method Details

__call() public method

..) it relies on this magic method. It allows us to handle some logic that is applicable across the board and also allows easy aliasing of methods (e.g. "o" for "option")... since it is a CLI library, such minified aliases would only be fitting :-).
public __call ( string $name, array $arguments ) : Command
$name string
$arguments array
return Command

__construct() public method

public __construct ( array | null $tokens = null )
$tokens array | null

__destruct() public method

public __destruct ( )

__toString() public method

public __toString ( ) : string
return string dump values

beepOnError() public method

Terminal beep on error
public beepOnError ( boolean $beep = true ) : Command
$beep boolean
return Command

current() public method

See also: Iterator
public current ( ) : mixed
return mixed value of current option

define() public static method

Factory style reads a little nicer
public static define ( array $tokens = null ) : Command
$tokens array defaults to $argv
return Command

doNotTrapErrors() public method

public doNotTrapErrors ( ) : Command
return Command

error() public method

public error ( Exception $e )
$e Exception

getArgumentValues() public method

public getArgumentValues ( ) : array
return array of argument values only If your command was `php filename -f flagvalue argument1 argument2` `getArguments` would return array("argument1", "argument2");

getArguments() public method

public getArguments ( ) : array
return array of argument `Option` only

getFlagValues() public method

public getFlagValues ( ) : array
return array of flag values only If your command was `php filename -f flagvalue argument1 argument2` `getFlags` would return array("-f" => "flagvalue");

getFlags() public method

public getFlags ( ) : array
return array of flag `Option` only

getHelp() public method

public getHelp ( ) : string
return string help docs

getOption() public method

public getOption ( string $option ) : Option
$option string
return Option

getOptions() public method

public getOptions ( ) : array
return array of `Option`s

getSize() public method

public getSize ( ) : integer
return integer

hasOption() public method

public hasOption ( string $option ) : boolean
$option string name (named option) or index (anonymous option)
return boolean

isParsed() public method

Has this Command instance parsed its arguments?
public isParsed ( ) : boolean
return boolean

key() public method

See also: Iterator
public key ( ) : integer
return integer

next() public method

See also: Iterator
public next ( )

offsetExists() public method

See also: ArrayAccess
public offsetExists ( string $offset ) : boolean
$offset string
return boolean

offsetGet() public method

See also: ArrayAccess
public offsetGet ( string $offset ) : mixed
$offset string
return mixed

offsetSet() public method

See also: ArrayAccess
public offsetSet ( string $offset, string $value )
$offset string
$value string

offsetUnset() public method

See also: ArrayAccess
public offsetUnset ( string $offset )
$offset string

parse() public method

public parse ( ) : void
return void

printHelp() public method

public printHelp ( )

rewind() public method

See also: Iterator
public rewind ( )

setHelp() public method

public setHelp ( string $help ) : Command
$help string
return Command

setTokens() public method

Rare that you would need to use this other than for testing, allows defining the cli tokens, instead of using $argv
public setTokens ( array $cli_tokens ) : Command
$cli_tokens array
return Command

trapErrors() public method

public trapErrors ( boolean $trap = true ) : Command
$trap boolean when true, exceptions will be caught by Commando and printed cleanly to standard error.
return Command

useDefaultHelp() public method

public useDefaultHelp ( boolean $help = true )
$help boolean

valid() public method

See also: Iterator
public valid ( ) : boolean
return boolean

Property Details

$methods public static property

Valid "option" options, mapped to their aliases
public static $methods