Console
in package
Class Console.
Table of Contents
- $arguments : array<string|int, mixed>
- Input arguments.
- $command : string
- The current command name.
- $commands : array<string|int, mixed>
- List of commands.
- $language : Language
- The Language instance.
- $options : array<string|int, mixed>
- Input options.
- __construct() : mixed
- Console constructor.
- addCommand() : static
- Add a command to the console.
- addCommands() : static
- Add many commands to the console.
- commandToArgs() : array<int, string>
- exec() : void
- getArgument() : string|null
- Get a specific argument or null.
- getArguments() : array<int, string>
- Get all arguments.
- getCommand() : Command|null
- Get an active command.
- getCommands() : array<string, Command>
- Get a list of active commands.
- getLanguage() : Language
- Get the Language instance.
- getOption() : bool|string|null
- Get a specific option or null.
- getOptions() : array<string, bool|string>
- Get all CLI options.
- hasCommand() : bool
- Tells if it has a command.
- removeCommand() : static
- Remove a command.
- removeCommands() : static
- Remove commands.
- run() : void
- Run the Console.
- setLanguage() : static
- Set the Language instance.
- prepare() : void
- Prepare information of the command line.
- reset() : void
- setDefaultCommands() : static
Properties
$arguments
Input arguments.
protected
array<string|int, mixed>
$arguments
= []
$command
The current command name.
protected
string
$command
= ''
$commands
List of commands.
protected
array<string|int, mixed>
$commands
= []
The command name as key and the object as value
$language
The Language instance.
protected
Language
$language
$options
Input options.
protected
array<string|int, mixed>
$options
= []
The option value as string or TRUE if it was passed without a value
Methods
__construct()
Console constructor.
public
__construct([Language|null $language = null ]) : mixed
Parameters
- $language : Language|null = null
Return values
mixed —addCommand()
Add a command to the console.
public
addCommand(Command|class-string<\Framework\CLI\Command> $command) : static
Parameters
- $command : Command|class-string<\Framework\CLI\Command>
-
A Command instance or the class FQN
Return values
static —addCommands()
Add many commands to the console.
public
addCommands(array<string|int, \Framework\CLI\Command|class-string<\Framework\CLI\Command>> $commands) : static
Parameters
- $commands : array<string|int, \Framework\CLI\Command|class-string<\Framework\CLI\Command>>
-
A list of Command instances or the classes FQN
Return values
static —commandToArgs()
public
static commandToArgs(string $command) : array<int, string>
Parameters
- $command : string
Tags
Return values
array<int, string> —exec()
public
exec(string $command) : void
Parameters
- $command : string
Return values
void —getArgument()
Get a specific argument or null.
public
getArgument(int $position) : string|null
Parameters
- $position : int
-
Argument position, starting from zero
Return values
string|null —The argument value or null if it was not set
getArguments()
Get all arguments.
public
getArguments() : array<int, string>
Return values
array<int, string> —getCommand()
Get an active command.
public
getCommand(string $name) : Command|null
Parameters
- $name : string
-
Command name
Return values
Command|null —The Command on success or null if not found
getCommands()
Get a list of active commands.
public
getCommands() : array<string, Command>
Return values
array<string, Command> —getLanguage()
Get the Language instance.
public
getLanguage() : Language
Return values
Language —getOption()
Get a specific option or null.
public
getOption(string $option) : bool|string|null
Parameters
- $option : string
Return values
bool|string|null —The option value as string, TRUE if it was passed without a value or NULL if the option was not set
getOptions()
Get all CLI options.
public
getOptions() : array<string, bool|string>
Return values
array<string, bool|string> —hasCommand()
Tells if it has a command.
public
hasCommand(string $name) : bool
Parameters
- $name : string
-
Command name
Return values
bool —removeCommand()
Remove a command.
public
removeCommand(string $name) : static
Parameters
- $name : string
-
Command name
Return values
static —removeCommands()
Remove commands.
public
removeCommands(array<string|int, string> $names) : static
Parameters
- $names : array<string|int, string>
-
Command names
Return values
static —run()
Run the Console.
public
run() : void
Return values
void —setLanguage()
Set the Language instance.
public
setLanguage([Language|null $language = null ]) : static
Parameters
- $language : Language|null = null
Return values
static —prepare()
Prepare information of the command line.
protected
prepare(array<int, string> $argumentValues) : void
[options] [arguments] [options] [options] -- [arguments] [command] [command] [options] [arguments] [options] [command] [options] -- [arguments] Short option: -l, -la === l = true, a = true Long option: --list, --all=vertical === list = true, all = vertical Only Long Options receive values: --foo=bar or --f=bar - "foo" and "f" are bar -foo=bar or -f=bar - all characters are true (f, o, =, b, a, r) After -- all values are arguments, also if is prefixed with - Without --, arguments and options can be mixed: -ls foo -x abc --a=e.
Parameters
- $argumentValues : array<int, string>
Return values
void —reset()
protected
reset() : void
Return values
void —setDefaultCommands()
protected
setDefaultCommands() : static