On this page
Class CommandRunner
Run CLI commands for the provided application.
- Cake\Console\CommandRunner uses Cake\Event\EventManagerTrait
Properties summary
-
$aliasesprotectedAlias mappings.array -
The application console commands are being run for.
$appprotected -
$rootprotectedThe root command name. Defaults tostringcake.
Method Summary
-
__construct() publicConstructor
-
createShell() protectedThe wrapper for creating shell instances.
-
getShell() protectedGet the shell instance for a given command name
-
run() publicRun the command contained in $argv.
-
setAliases() publicReplace the entire alias map for a runner.
Method Detail
__construct()source public
__construct( Cake\Core\ConsoleApplicationInterface $app , string $root 'cake' )
Constructor
Parameters
Cake\Core\ConsoleApplicationInterface$app- The application to run CLI commands for.
-
string
$rootoptional 'cake' - The root command name to be removed from argv.
createShell()source protected
createShell( string $className , Cake\Console\ConsoleIo $io )
The wrapper for creating shell instances.
Parameters
-
string
$className - Shell class name.
Cake\Console\ConsoleIo$io- The IO wrapper for the created shell class.
Returns
Cake\Console\ShellgetShell()source protected
getShell( Cake\Console\ConsoleIo $io , Cake\Console\CommandCollection $commands , string $name )
Get the shell instance for a given command name
Parameters
Cake\Console\ConsoleIo$io- The IO wrapper for the created shell class.
Cake\Console\CommandCollection$commands- The command collection to find the shell in.
-
string
$name - The command name to find
Returns
Cake\Console\Shellrun()source public
run( array $argv , Cake\Console\ConsoleIo $io null )
Run the command contained in $argv.
Use the application to do the following:
- Bootstrap the application
- Create the CommandCollection using the console() hook on the application.
- Trigger the
Console.buildCommandsevent of auto-wiring plugins. - Run the requested command.
Parameters
-
array
$argv - The arguments from the CLI environment.
Cake\Console\ConsoleIo$iooptional null- The ConsoleIo instance. Used primarily for testing.
Returns
integerThe exit code of the command.
Throws
RuntimeExceptionsetAliases()source public
setAliases( array $aliases )
Replace the entire alias map for a runner.
Aliases allow you to define alternate names for commands in the collection. This can be useful to add top level switches like --version or -h
Usage
$runner->setAliases(['--version' => 'version']);
Parameters
-
array
$aliases - The map of aliases to replace.
Returns
$this
Properties detail
$appsource
protected Cake\Core\ConsoleApplicationInterface
The application console commands are being run for.
© 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.CommandRunner.html