Class ShellDispatcher
Shell dispatcher handles dispatching cli commands.
Consult /bin/cake.php for how this class is used in practice.
Direct Subclasses
Properties summary
- List of connected aliases.
array
-
$args
publicContains arguments parsed from the command line.array
Method Summary
- __construct() publicConstructor
- _bootstrap() protectedInitializes the environment and loads the CakePHP core.
- _createShell() protectedCreate the given shell name, and set the plugin property
- _dispatch() protectedDispatch a request.
- _handleAlias() protectedIf the input matches an alias, return the aliased shell name
- _initEnvironment() protectedDefines current working environment.
- _shellExists() protectedCheck if a shell class exists for the given name.
- addShortPluginAliases() publicFor all loaded plugins, add a short alias
- Add an alias for a shell command.
- dispatch() publicDispatches a CLI request
- findShell() publicGet shell to use, either plugin shell or application shell
- help() publicShows console help. Performs an internal dispatch to the CommandList Shell
- Clear any aliases that have been set.
- Run the dispatcher
- shiftArgs() publicRemoves first argument and shifts other arguments up
- version() publicPrints the currently installed version of CakePHP. Performs an internal dispatch to the CommandList Shell
Method Detail
__construct()source public
__construct( array $args [] , boolean $bootstrap true )
Constructor
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
- array
$args
optional [] - the argv from PHP
- boolean
$bootstrap
optional true - Should the environment be bootstrapped.
_bootstrap()source protected
_bootstrap( )
Initializes the environment and loads the CakePHP core.
Returns
booleanSuccess.
_createShell()source protected
_createShell( string $className , string $shortName )
Create the given shell name, and set the plugin property
Parameters
- string
$className
- The class name to instantiate
- string
$shortName
- The plugin-prefixed shell name
Returns
Cake\Console\Shell
A shell instance.
_dispatch()source protected
_dispatch( array $extra [] )
Dispatch a request.
Parameters
- array
$extra
optional [] 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
Returns
booleanThrows
Cake\Console\Exception\MissingShellMethodException
_handleAlias()source protected
_handleAlias( string $shell )
If the input matches an alias, return the aliased shell name
Parameters
- string
$shell
- Optionally the name of a plugin or alias
Returns
stringShell name with plugin prefix
_initEnvironment()source protected
_initEnvironment( )
Defines current working environment.
Throws
Cake\Core\Exception\Exception
_shellExists()source protected
_shellExists( string $shell )
Check if a shell class exists for the given name.
Parameters
- string
$shell
- The shell name to look for.
Returns
string|booleanEither the classname or false.
addShortPluginAliases()source public
addShortPluginAliases( )
For all loaded plugins, add a short alias
This permits a plugin which implements a shell of the same name to be accessed Using the shell name alone
Returns
arraythe resultant list of aliases
alias()source public static
alias( string $short , string|null $original null )
Add an alias for a shell command.
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
- string
$short
- The new short name for the shell.
- string|null
$original
optional null - The original full name for the shell.
Returns
string|falseThe aliased class name, or false if the alias does not exist
dispatch()source public
dispatch( array $extra [] )
Dispatches a CLI request
Converts a shell command result into an exit code. Null/True are treated as success. All other return values are an error.
Parameters
- array
$extra
optional [] 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
Returns
integerThe cli command exit code. 0 is success.
findShell()source public
findShell( string $shell )
Get shell to use, either plugin shell or application shell
All paths in the loaded shell paths are searched, handles alias dereferencing
Parameters
- string
$shell
- Optionally the name of a plugin
Returns
Cake\Console\Shell
A shell instance.
Throws
Cake\Console\Exception\MissingShellException
when errors are encountered.
help()source public
help( )
Shows console help. Performs an internal dispatch to the CommandList Shell
run()source public static
run( array $argv , array $extra [] )
Run the dispatcher
Parameters
- array
$argv
- The argv from PHP
- array
$extra
optional [] - Extra parameters
Returns
integerThe exit code of the shell process.
shiftArgs()source public
shiftArgs( )
Removes first argument and shifts other arguments up
Returns
mixedNull if there are no arguments otherwise the shifted argument
version()source public
version( )
Prints the currently installed version of CakePHP. Performs an internal dispatch to the CommandList Shell
Properties detail
© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.4/class-Cake.Console.ShellDispatcher.html