class Console extends AbstractConsole (View source)

Class Console

Properties

IOInterface $io Property io. from AbstractConsole

Methods

__construct(IOInterface $io = null, Structure $config = null)

Class init.

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

Write a string to standard output.

string
in()

Get a value from standard input.

void
close(integer|string $message)

Method to close the application.

void
execute()

Execute the application.

mixed
get(string $key, mixed $default = null)

Returns a property of the object or the default value if the property is not set.

mixed
set(string $key, mixed $value = null)

Modifies a property of the object, creating it if it does not already exist.

setConfiguration(Structure $config)

Sets the configuration for the application.

getConfig()

Method to get property Config

setConfig(Structure $config)

Method to set property config

setDescriptor(DescriptorHelperInterface $descriptor)

Method to set property descriptor

string
describeCommand(AbstractCommand $command)

describeCommand

int
doExecute(AbstractCommand $command = null)

Method to run the application routines.

int
executeByPath(string $arguments, array $options = array(), IOInterface $io = null)

executeByPath

registerRootCommand()

Register default command.

register(string $name)

Register a new Console.

addCommand(AbstractCommand|string $command)

Add a new command object.

getCommand(string $path)

Get command by path.

setAutoExit(boolean $boolean)

Sets whether to automatically exit after a command execution or not.

getRootCommand()

Get the default command.

string
getVersion()

Get version.

setVersion(string $version)

Set version.

string
getDescription()

Get description.

setDescription(string $description)

Set description.

setHandler(callable $closure)

Set execute code to default command.

$this
setUsage(string $usage)

setUsage

$this
setHelp(string $help)

setHelp

string
getHelp()

Method to get property Help

string
getTitle()

Method to get property Title

setTitle(string $title)

Method to set property title

Details

at line line 84
__construct(IOInterface $io = null, Structure $config = null)

Class init.

Parameters

IOInterface $io An optional argument to provide dependency injection for the application's IO object.
Structure $config An optional argument to provide dependency injection for the config object.

AbstractConsole 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

AbstractConsole Instance of $this to allow chaining.

string in()

Get a value from standard input.

Return Value

string The input string from standard input.

IOInterface getIO()

getIo

Return Value

IOInterface

AbstractConsole setIO(IOInterface $io)

setIo

Parameters

IOInterface $io

Return Value

AbstractConsole Return self to support chaining.

void close(integer|string $message)

Method to close the application.

Parameters

integer|string $message The exit code (optional; default is 0).

Return Value

void

at line line 100
void execute()

Execute the application.

Return Value

void

mixed get(string $key, mixed $default = null)

Returns a property of the object or the default value if the property is not set.

Parameters

string $key The name of the property.
mixed $default The default value (optional) if none is set.

Return Value

mixed The value of the configuration.

mixed set(string $key, mixed $value = null)

Modifies a property of the object, creating it if it does not already exist.

Parameters

string $key The name of the property.
mixed $value The value of the property to set (optional).

Return Value

mixed Previous value of the property

AbstractConsole setConfiguration(Structure $config)

Sets the configuration for the application.

Parameters

Structure $config A structure object holding the configuration.

Return Value

AbstractConsole Returns itself to support chaining.

Structure getConfig()

Method to get property Config

Return Value

Structure

AbstractConsole setConfig(Structure $config)

Method to set property config

Parameters

Structure $config

Return Value

AbstractConsole Return self to support chaining.

AbstractConsole setDescriptor(DescriptorHelperInterface $descriptor)

Method to set property descriptor

Parameters

DescriptorHelperInterface $descriptor

Return Value

AbstractConsole Return self to support chaining.

string describeCommand(AbstractCommand $command)

describeCommand

Parameters

AbstractCommand $command

Return Value

string

at line line 127
int doExecute(AbstractCommand $command = null)

Method to run the application routines.

Parameters

AbstractCommand $command The Command object to execute, default will be rootCommand.

Return Value

int The Unix Console/Shell exit code.

Exceptions

LogicException
Exception

See also

http://tldp.org/LDP/abs/html/exitcodes.html

at line line 176
int executeByPath(string $arguments, array $options = array(), IOInterface $io = null)

executeByPath

Parameters

string $arguments
array $options
IOInterface $io

Return Value

int

Exceptions

Exception

at line line 205
Console registerRootCommand()

Register default command.

Return Value

Console Return this object to support chaining.

at line line 231
AbstractCommand register(string $name)

Register a new Console.

Parameters

string $name The command name.

Return Value

AbstractCommand The created commend.

at line line 247
AbstractCommand addCommand(AbstractCommand|string $command)

Add a new command object.

If a command with the same name already exists, it will be overridden.

Parameters

AbstractCommand|string $command A Console object.

Return Value

AbstractCommand The registered command.

at line line 265
AbstractCommand getCommand(string $path)

Get command by path.

Example: getCommand('foo/bar/baz');

Parameters

string $path The path or name of child.

Return Value

AbstractCommand

at line line 279
Console setAutoExit(boolean $boolean)

Sets whether to automatically exit after a command execution or not.

Parameters

boolean $boolean Whether to automatically exit after a command execution or not.

Return Value

Console Return this object to support chaining.

at line line 293
AbstractCommand getRootCommand()

Get the default command.

Return Value

AbstractCommand Default command.

at line line 303
string getVersion()

Get version.

Return Value

string Application version.

at line line 317
Console setVersion(string $version)

Set version.

Parameters

string $version Set version of this application.

Return Value

Console Return this object to support chaining.

at line line 331
string getDescription()

Get description.

Return Value

string Application description.

at line line 345
Console setDescription(string $description)

Set description.

Parameters

string $description description of this application.

Return Value

Console Return this object to support chaining.

at line line 361
Console setHandler(callable $closure)

Set execute code to default command.

Parameters

callable $closure Console execute code.

Return Value

Console Return this object to support chaining.

at line line 375
$this setUsage(string $usage)

setUsage

Parameters

string $usage

Return Value

$this

at line line 389
$this setHelp(string $help)

setHelp

Parameters

string $help

Return Value

$this

at line line 401
string getHelp()

Method to get property Help

Return Value

string

at line line 411
string getTitle()

Method to get property Title

Return Value

string

at line line 423
Console setTitle(string $title)

Method to set property title

Parameters

string $title

Return Value

Console Return self to support chaining.