class Console (View source)

Constants

REGEX_PARSE_OPTION

Properties

protected $namespacePrefix

Methods

action(string $name, string|callable $callback)

Register callable, console controller, and Command instance for a CLI command

setNamespace(string $prefix)

Prefixes the namespace to command controller classes

int
exec(array $arguments)

Receives the arguments to execute the command If the command is not found, an exception will be thrown

Command|null
getCommand(string $name)

Get a command by name

static string
run(string $command, array $args = array(), int $code = 0)

Shortcut to execute predefined commands or commands from system/console.php

static array<string, string>
parseOptions(array $entries)

Parse the arguments (usually received from the $argv variable) into an associative array, based on the long and short format options.

Details

Command action(string $name, string|callable $callback)

Register callable, console controller, and Command instance for a CLI command

Parameters

string $name
string|callable $callback

Return Value

Command

setNamespace(string $prefix)

Prefixes the namespace to command controller classes

Parameters

string $prefix

int exec(array $arguments)

Receives the arguments to execute the command If the command is not found, an exception will be thrown

Parameters

array $arguments

Define $argv without changes

Return Value

int

Exceptions

Exception

Command|null getCommand(string $name)

Get a command by name

Parameters

string $name

Return Value

Command|null

static string run(string $command, array $args = array(), int $code = 0)

Shortcut to execute predefined commands or commands from system/console.php

Parameters

string $command

The command that will be executed

array $args

Argument list

int $code

If the $code argument is present, then the return status of the executed command will be written to this variable

Return Value

string

Exceptions

Exception

static protected array<string, string> parseOptions(array $entries)

Parse the arguments (usually received from the $argv variable) into an associative array, based on the long and short format options.

Note: It is possible to extend the Console class by creating a subclass that overrides the parser, allowing it to use a different options structure.

Parameters

array $entries

Return Value

array<string, string>

Exceptions

Exception