ShellDispatcher
in package
Shell dispatcher handles dispatching CLI commands.
ShellDispatcher and Shell will be removed in 5.0
Consult /bin/cake.php for how this class is used in practice.
Table of Contents
Properties
- $args : array<string|int, mixed>
- Contains arguments parsed from the command line.
- $_aliases : array<string, string>
- List of connected aliases.
Methods
- __construct() : mixed
- Constructor
- addShortPluginAliases() : array<string|int, mixed>
- For all loaded plugins, add a short alias
- alias() : string|null
- Add an alias for a shell command.
- dispatch() : int
- Dispatches a CLI request
- findShell() : Shell
- Get shell to use, either plugin shell or application shell
- help() : void
- Shows console help. Performs an internal dispatch to the CommandList Shell
- resetAliases() : void
- Clear any aliases that have been set.
- run() : int
- Run the dispatcher
- shiftArgs() : mixed
- Removes first argument and shifts other arguments up
- version() : void
- Prints the currently installed version of CakePHP. Performs an internal dispatch to the CommandList Shell
- _bootstrap() : void
- Initializes the environment and loads the CakePHP core.
- _createShell() : Shell
- Create the given shell name, and set the plugin property
- _dispatch() : int|bool|null
- Dispatch a request.
- _handleAlias() : string
- If the input matches an alias, return the aliased shell name
- _initEnvironment() : void
- Defines current working environment.
- _shellExists() : string|null
- Check if a shell class exists for the given name.
Properties
$args
Contains arguments parsed from the command line.
public
array<string|int, mixed>
$args
= []
$_aliases
List of connected aliases.
protected
static array<string, string>
$_aliases
= []
Methods
__construct()
Constructor
public
__construct([array<string|int, mixed> $args = [] ][, bool $bootstrap = true ]) : mixed
The execution of the script is stopped after dispatching the request with a status code of either 0 or 1 according to the result of the dispatch.
Parameters
- $args : array<string|int, mixed> = []
-
the argv from PHP
- $bootstrap : bool = true
-
Should the environment be bootstrapped.
addShortPluginAliases()
For all loaded plugins, add a short alias
public
addShortPluginAliases() : array<string|int, mixed>
This permits a plugin which implements a shell of the same name to be accessed Using the shell name alone
Return values
array<string|int, mixed> —the resultant list of aliases
alias()
Add an alias for a shell command.
public
static alias(string $short[, string|null $original = null ]) : string|null
Aliases allow you to call shells by alternate names. This is most useful when dealing with plugin shells that you want to have shorter names for.
If you re-use an alias the last alias set will be the one available.
Usage
Aliasing a shell named ClassName:
$this->alias('alias', 'ClassName');
Getting the original name for a given alias:
$this->alias('alias');
Parameters
- $short : string
-
The new short name for the shell.
- $original : string|null = null
-
The original full name for the shell.
Return values
string|null —The aliased class name, or null if the alias does not exist
dispatch()
Dispatches a CLI request
public
dispatch([array<string|int, mixed> $extra = [] ]) : int
Converts a shell command result into an exit code. Null/True are treated as success. All other return values are an error.
Parameters
- $extra : array<string|int, mixed> = []
-
Extra parameters that you can manually pass to the Shell to be dispatched. Built-in extra parameter is :
-
requested
: if used, will prevent the Shell welcome message to be displayed
-
Return values
int —The CLI command exit code. 0 is success.
findShell()
Get shell to use, either plugin shell or application shell
public
findShell(string $shell) : Shell
All paths in the loaded shell paths are searched, handles alias dereferencing
Parameters
- $shell : string
-
Optionally the name of a plugin
Tags
Return values
Shell —A shell instance.
help()
Shows console help. Performs an internal dispatch to the CommandList Shell
public
help() : void
resetAliases()
Clear any aliases that have been set.
public
static resetAliases() : void
run()
Run the dispatcher
public
static run(array<string|int, mixed> $argv[, array<string|int, mixed> $extra = [] ]) : int
Parameters
- $argv : array<string|int, mixed>
-
The argv from PHP
- $extra : array<string|int, mixed> = []
-
Extra parameters
Return values
int —The exit code of the shell process.
shiftArgs()
Removes first argument and shifts other arguments up
public
shiftArgs() : mixed
Return values
mixed —Null if there are no arguments otherwise the shifted argument
version()
Prints the currently installed version of CakePHP. Performs an internal dispatch to the CommandList Shell
public
version() : void
_bootstrap()
Initializes the environment and loads the CakePHP core.
protected
_bootstrap() : void
_createShell()
Create the given shell name, and set the plugin property
protected
_createShell(string $className, string $shortName) : Shell
Parameters
- $className : string
-
The class name to instantiate
- $shortName : string
-
The plugin-prefixed shell name
Return values
Shell —A shell instance.
_dispatch()
Dispatch a request.
protected
_dispatch([array<string|int, mixed> $extra = [] ]) : int|bool|null
Parameters
- $extra : array<string|int, mixed> = []
-
Extra parameters that you can manually pass to the Shell to be dispatched. Built-in extra parameter is :
-
requested
: if used, will prevent the Shell welcome message to be displayed
-
Tags
Return values
int|bool|null_handleAlias()
If the input matches an alias, return the aliased shell name
protected
_handleAlias(string $shell) : string
Parameters
- $shell : string
-
Optionally the name of a plugin or alias
Return values
string —Shell name with plugin prefix
_initEnvironment()
Defines current working environment.
protected
_initEnvironment() : void
Tags
_shellExists()
Check if a shell class exists for the given name.
protected
_shellExists(string $shell) : string|null
Parameters
- $shell : string
-
The shell name to look for.
Return values
string|null —Either the classname or null.