class AbstractCommand implements ArrayAccess (View source)

Abstract Console class.

Methods

__construct(string $name = null, IOInterface $io = null, AbstractCommand $parent = null)

Console constructor.

mixed
execute()

Execute this command.

getIO()

Method to get property Io

setIO(IOInterface $io)

Method to set property io

setParent(AbstractCommand $parent = null)

Parent command setter.

getParent()

Get Parent Command.

addCommand(string|AbstractCommand $command, string $description = null, Option[] $options = array(), Closure $handler = null)

Add an argument(sub command) setting.

null|string
getArgument(int $offset, callable|mixed $default = null)

Get argument by offset or return default.

addChild(string|AbstractCommand $argument, string $description = null, Option[] $options = array(), Closure $handler = null)

Alias of addCommand if someone think child is more semantic.

getChild(string $path)

Get a argument(command) by name path.

array
getChildren()

Get children array.

setChildren(array $children)

Batch set children (sub commands).

addOption(mixed $option, mixed $default = null, string $description = null)

Add a option object to this command.

addGlobalOption(mixed $option, mixed $default = null, string $description = null)

Add a option object to this command.

mixed
getOption(string $name, string $default = null)

Get value from an option.

Option[]
getOptions(boolean $global = false)

Get options as array.

getOptionSet(boolean $global = false)

Get option set object.

array
getAllOptions()

Get all options include global.

setOptions(mixed $options)

Batch add options to command.

setOptionAliases(mixed $aliases, string $name, bool $global = false)

set the option alias.

string
getDescription()

The command description getter.

description(string $description)

The command description setter.

string
getName()

Console name getter.

setName(string $name)

Console name setter.

getHandler()

Console execute code getter.

handler(callable $handler = null)

Console execute code setter.

getApplication()

Get the application.

setApplication(Console $application)

Set the application.

string
getHelp()

Get the help manual.

help(string $help)

Sets the help manual

string
getUsage()

Get the usage.

usage(string $usage)

Sets the usage to tell user how to use this command.

void
renderAlternatives(string $wrongName, CommandNotFoundException $exception)

Render auto complete alternatives.

void
renderException(Exception $exception)

Render exception for debugging.

void
error(Exception|string $exception)

Raise error message.

out(string $text = '', boolean $nl = true)

Write a string to standard output.

err(string $text = '', boolean $nl = true)

Write a string to standard error output.

string
in(string $question = '')

Get a value from standard input.

void
offsetSet(mixed $offset, AbstractCommand $value)

Set child command, note the key is no use, we use command name as key.

boolean
offsetExists(string $offset)

Is a child exists?

void
offsetUnset(string $offset)

Unset a child command.

offsetGet(string $offset)

Get a command by name.

Details

at line line 137
__construct(string $name = null, IOInterface $io = null, AbstractCommand $parent = null)

Console constructor.

Parameters

string $name Console name.
IOInterface $io Cli input object.
AbstractCommand $parent Parent Console.

Exceptions

LogicException

at line line 162
mixed execute()

Execute this command.

Return Value

mixed Executed result or exit code.

Exceptions

Exception

at line line 313
IOInterface getIO()

Method to get property Io

Return Value

IOInterface

at line line 325
AbstractCommand setIO(IOInterface $io)

Method to set property io

Parameters

IOInterface $io

Return Value

AbstractCommand Return self to support chaining.

at line line 341
AbstractCommand setParent(AbstractCommand $parent = null)

Parent command setter.

Parameters

AbstractCommand $parent The parent comment.

Return Value

AbstractCommand Return this object to support chaining.

at line line 355
AbstractCommand getParent()

Get Parent Command.

Return Value

AbstractCommand

at line line 373
AbstractCommand addCommand(string|AbstractCommand $command, string $description = null, Option[] $options = array(), Closure $handler = null)

Add an argument(sub command) setting.

Parameters

string|AbstractCommand $command The argument name or Console object. If we just send a string, the object will auto create.
string $description Console description.
Option[] $options Console options.
Closure $handler The closure to execute.

Return Value

AbstractCommand Return this object to support chaining.

at line line 429
null|string getArgument(int $offset, callable|mixed $default = null)

Get argument by offset or return default.

Parameters

int $offset Argument offset.
callable|mixed $default Default value, if is a callable, will execute it.

Return Value

null|string Values from argument or user input.

at line line 459
AbstractCommand addChild(string|AbstractCommand $argument, string $description = null, Option[] $options = array(), Closure $handler = null)

Alias of addCommand if someone think child is more semantic.

Parameters

string|AbstractCommand $argument The argument name or Console object. If we just send a string, the object will auto create.
string $description Console description.
Option[] $options Console options.
Closure $handler The closure to execute.

Return Value

AbstractCommand Return this object to support chaining.

at line line 473
AbstractCommand|null getChild(string $path)

Get a argument(command) by name path.

Parameters

string $path Command name path.

Return Value

AbstractCommand|null Return command or null.

at line line 501
array getChildren()

Get children array.

Return Value

array children.

at line line 515
AbstractCommand setChildren(array $children)

Batch set children (sub commands).

Parameters

array $children An array include argument objects.

Return Value

AbstractCommand Return this object to support chaining.

at line line 539
Option addOption(mixed $option, mixed $default = null, string $description = null)

Add a option object to this command.

Parameters

mixed $option The option name. Can be a string, an array or an object. If we use array, the first element will be option name, others will be alias.
mixed $default The default value when we get a non-exists option.
string $description The option description.

Return Value

Option Return Option object.

at line line 572
Option addGlobalOption(mixed $option, mixed $default = null, string $description = null)

Add a option object to this command.

Parameters

mixed $option The option name. Can be a string, an array or an object. If we use array, the first element will be option name, others will be alias.
mixed $default The default value when we get a non-exists option.
string $description The option description.

Return Value

Option Return Option object.

at line line 611
mixed getOption(string $name, string $default = null)

Get value from an option.

If the name not found, we use alias to find options.

Parameters

string $name The option name.
string $default The default value when option not set.

Return Value

mixed The option value we want to get or default value if option not exists.

at line line 649
Option[] getOptions(boolean $global = false)

Get options as array.

Parameters

boolean $global is Global options.

Return Value

Option[] The options array.

at line line 663
OptionSet getOptionSet(boolean $global = false)

Get option set object.

Parameters

boolean $global is Global options.

Return Value

OptionSet The options array.

at line line 675
array getAllOptions()

Get all options include global.

Return Value

array The options array.

at line line 689
AbstractCommand setOptions(mixed $options)

Batch add options to command.

Parameters

mixed $options An options array.

Return Value

AbstractCommand Return this object to support chaining.

at line line 712
AbstractCommand setOptionAliases(mixed $aliases, string $name, bool $global = false)

set the option alias.

Parameters

mixed $aliases The alias to map this option.
string $name The option name.
bool $global Is global option?

Return Value

AbstractCommand Return this object to support chaining.

at line line 733
string getDescription()

The command description getter.

Return Value

string Console description.

at line line 747
AbstractCommand description(string $description)

The command description setter.

Parameters

string $description Console description.

Return Value

AbstractCommand Return this object to support chaining.

at line line 761
string getName()

Console name getter.

Return Value

string Console name.

at line line 775
AbstractCommand setName(string $name)

Console name setter.

Parameters

string $name Console name.

Return Value

AbstractCommand Return this object to support chaining.

at line line 789
Closure getHandler()

Console execute code getter.

Return Value

Closure Console execute code.

at line line 803
AbstractCommand handler(callable $handler = null)

Console execute code setter.

Parameters

callable $handler Console execute handler.

Return Value

AbstractCommand Return this object to support chaining.

at line line 817
Console getApplication()

Get the application.

Return Value

Console Console application.

at line line 831
AbstractCommand setApplication(Console $application)

Set the application.

Parameters

Console $application Application object.

Return Value

AbstractCommand Return this object to support chaining.

at line line 845
string getHelp()

Get the help manual.

Return Value

string Help of this Command.

at line line 859
AbstractCommand help(string $help)

Sets the help manual

Parameters

string $help The help manual.

Return Value

AbstractCommand Return this object to support chaining.

at line line 873
string getUsage()

Get the usage.

Return Value

string Usage of this command.

at line line 887
AbstractCommand usage(string $usage)

Sets the usage to tell user how to use this command.

Parameters

string $usage Usage of this command.

Return Value

AbstractCommand Return this object to support chaining.

at line line 904
void renderAlternatives(string $wrongName, CommandNotFoundException $exception)

Render auto complete alternatives.

Parameters

string $wrongName The wrong command name to auto completed.
CommandNotFoundException $exception The exception of wrong argument.

Return Value

void

at line line 953
void renderException(Exception $exception)

Render exception for debugging.

Parameters

Exception $exception The exception we want to render.

Return Value

void

at line line 988
void error(Exception|string $exception)

Raise error message.

Parameters

Exception|string $exception Exception object or message string.

Return Value

void

Exceptions

Exception

at line line 1008
AbstractCommand out(string $text = '', boolean $nl = true)

Write a string to standard output.

Parameters

string $text The text to display.
boolean $nl True (default) to append a new line at the end of the output string.

Return Value

AbstractCommand Instance of $this to allow chaining.

at line line 1030
AbstractCommand err(string $text = '', boolean $nl = true)

Write a string to standard error output.

Parameters

string $text The text to display.
boolean $nl True (default) to append a new line at the end of the output string.

Return Value

AbstractCommand Instance of $this to allow chaining.

at line line 1046
string in(string $question = '')

Get a value from standard input.

Parameters

string $question The question you want to ask user.

Return Value

string The input string from standard input.

at line line 1066
void offsetSet(mixed $offset, AbstractCommand $value)

Set child command, note the key is no use, we use command name as key.

Parameters

mixed $offset No use here.
AbstractCommand $value Command object.

Return Value

void

at line line 1080
boolean offsetExists(string $offset)

Is a child exists?

Parameters

string $offset The command name to get command.

Return Value

boolean True if command exists.

at line line 1094
void offsetUnset(string $offset)

Unset a child command.

Parameters

string $offset The command name to remove.

Return Value

void

at line line 1108
AbstractCommand|null offsetGet(string $offset)

Get a command by name.

Parameters

string $offset The command name to get command.

Return Value

AbstractCommand|null Return command object if found.