PHP Class Cake\Console\ShellDispatcher

Consult /bin/cake.php for how this class is used in practice.
Datei anzeigen Open project: cakephp/cakephp Class Usage Examples

Public Properties

Property Type Description
$args array Contains arguments parsed from the command line.

Protected Properties

Property Type Description
$_aliases array List of connected aliases.

Public Methods

Method Description
__construct ( array $args = [], boolean $bootstrap = true ) Constructor
addShortPluginAliases ( ) : array For all loaded plugins, add a short alias
alias ( string $short, string | null $original = null ) : string | false Add an alias for a shell command.
dispatch ( array $extra = [] ) : integer Dispatches a CLI request
findShell ( string $shell ) : 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 ( array $argv, array $extra = [] ) : integer 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

Protected Methods

Method Description
_bootstrap ( ) : boolean Initializes the environment and loads the CakePHP core.
_createShell ( string $className, string $shortName ) : Shell Create the given shell name, and set the plugin property
_dispatch ( array $extra = [] ) : boolean Dispatch a request.
_handleAlias ( string $shell ) : string If the input matches an alias, return the aliased shell name
_initEnvironment ( ) : void Defines current working environment.
_shellExists ( string $shell ) : string | boolean Check if a shell class exists for the given name.

Method Details

__construct() public method

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.
public __construct ( array $args = [], boolean $bootstrap = true )
$args array the argv from PHP
$bootstrap boolean Should the environment be bootstrapped.

_bootstrap() protected method

Initializes the environment and loads the CakePHP core.
protected _bootstrap ( ) : boolean
return boolean Success.

_createShell() protected method

Create the given shell name, and set the plugin property
protected _createShell ( string $className, string $shortName ) : Shell
$className string The class name to instantiate
$shortName string The plugin-prefixed shell name
return Shell A shell instance.

_dispatch() protected method

Dispatch a request.
protected _dispatch ( array $extra = [] ) : boolean
$extra array 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 boolean

_handleAlias() protected method

If the input matches an alias, return the aliased shell name
protected _handleAlias ( string $shell ) : string
$shell string Optionally the name of a plugin or alias
return string Shell name with plugin prefix

_initEnvironment() protected method

Defines current working environment.
protected _initEnvironment ( ) : void
return void

_shellExists() protected method

Check if a shell class exists for the given name.
protected _shellExists ( string $shell ) : string | boolean
$shell string The shell name to look for.
return string | boolean Either the classname or false.

addShortPluginAliases() public method

This permits a plugin which implements a shell of the same name to be accessed Using the shell name alone
public addShortPluginAliases ( ) : array
return array the resultant list of aliases

alias() public static method

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');
public static alias ( string $short, string | null $original = null ) : string | false
$short string The new short name for the shell.
$original string | null The original full name for the shell.
return string | false The aliased class name, or false if the alias does not exist

dispatch() public method

Converts a shell command result into an exit code. Null/True are treated as success. All other return values are an error.
public dispatch ( array $extra = [] ) : integer
$extra array 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 integer The cli command exit code. 0 is success.

findShell() public method

All paths in the loaded shell paths are searched, handles alias dereferencing
public findShell ( string $shell ) : Shell
$shell string Optionally the name of a plugin
return Shell A shell instance.

help() public method

Shows console help. Performs an internal dispatch to the CommandList Shell
public help ( ) : void
return void

resetAliases() public static method

Clear any aliases that have been set.
public static resetAliases ( ) : void
return void

run() public static method

Run the dispatcher
public static run ( array $argv, array $extra = [] ) : integer
$argv array The argv from PHP
$extra array Extra parameters
return integer The exit code of the shell process.

shiftArgs() public method

Removes first argument and shifts other arguments up
public shiftArgs ( ) : mixed
return mixed Null if there are no arguments otherwise the shifted argument

version() public method

Prints the currently installed version of CakePHP. Performs an internal dispatch to the CommandList Shell
public version ( ) : void
return void

Property Details

$_aliases protected_oe static_oe property

List of connected aliases.
protected static array $_aliases
return array

$args public_oe property

Contains arguments parsed from the command line.
public array $args
return array