\Cake\TestSuiteLegacyShellDispatcher

Allows injecting mock IO into shells

Consult /bin/cake.php for how this class is used in practice.

Summary

Methods
Properties
Constants
__construct()
alias()
resetAliases()
run()
dispatch()
addShortPluginAliases()
findShell()
shiftArgs()
help()
version()
$args
No constants found
_initEnvironment()
_bootstrap()
_dispatch()
_handleAlias()
_shellExists()
_createShell()
$_aliases
$_io
N/A
No private methods found
No private properties found
N/A

Properties

$args

$args : array

Contains arguments parsed from the command line.

Type

array

$_aliases

$_aliases : array

List of connected aliases.

Type

array

Methods

__construct()

__construct(array  $args = array(), boolean  $bootstrap = true, \Cake\Console\ConsoleIo  $io = null) 

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

Argument array

boolean $bootstrap

Initialize environment

\Cake\Console\ConsoleIo $io

ConsoleIo

alias()

alias(string  $short, string|null  $original = null) : string|false

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

The original full name for the shell.

Returns

string|false —

The aliased class name, or false if the alias does not exist

resetAliases()

resetAliases() : void

Clear any aliases that have been set.

run()

run(array  $argv, array  $extra = array()) : integer

Run the dispatcher

Parameters

array $argv

The argv from PHP

array $extra

Extra parameters

Returns

integer —

The exit code of the shell process.

dispatch()

dispatch(array  $extra = array()) : integer

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

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

integer —

The cli command exit code. 0 is success.

addShortPluginAliases()

addShortPluginAliases() : array

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

array —

the resultant list of aliases

findShell()

findShell(string  $shell) : \Cake\Console\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

Throws

\Cake\Console\Exception\MissingShellException

when errors are encountered.

Returns

\Cake\Console\Shell

A shell instance.

shiftArgs()

shiftArgs() : mixed

Removes first argument and shifts other arguments up

Returns

mixed —

Null if there are no arguments otherwise the shifted argument

help()

help() : void

Shows console help. Performs an internal dispatch to the CommandList Shell

version()

version() : void

Prints the currently installed version of CakePHP. Performs an internal dispatch to the CommandList Shell

_initEnvironment()

_initEnvironment() : void

Defines current working environment.

Throws

\Cake\Core\Exception\Exception

_bootstrap()

_bootstrap() : boolean

Initializes the environment and loads the CakePHP core.

Returns

boolean —

Success.

_dispatch()

_dispatch(array  $extra = array()) : boolean|integer|null

Dispatch a request.

Parameters

array $extra

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

Throws

\Cake\Console\Exception\MissingShellMethodException

Returns

boolean|integer|null

_handleAlias()

_handleAlias(string  $shell) : string

If the input matches an alias, return the aliased shell name

Parameters

string $shell

Optionally the name of a plugin or alias

Returns

string —

Shell name with plugin prefix

_shellExists()

_shellExists(string  $shell) : string|boolean

Check if a shell class exists for the given name.

Parameters

string $shell

The shell name to look for.

Returns

string|boolean —

Either the classname or false.

_createShell()

_createShell(string  $className, string  $shortName) : \Cake\Console\Shell

Injects mock and stub io components into the shell

Parameters

string $className

Class name

string $shortName

Short name

Returns

\Cake\Console\Shell