Class CommandRunner

Run CLI commands for the provided application.

Cake\Console\CommandRunner uses Cake\Event\EventManagerTrait
Namespace: Cake\Console
Location: Console/CommandRunner.php

Properties summary

Method Summary

  • __construct() public
    Constructor
  • createShell() protected
    The wrapper for creating shell instances.
  • getShell() protected
    Get the shell instance for a given command name
  • run() public
    Run the command contained in $argv.
  • setAliases() public
    Replace 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 $root optional '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\Shell

getShell()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\Shell

run()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.buildCommands event of auto-wiring plugins.
  • Run the requested command.

Parameters

array $argv
The arguments from the CLI environment.
Cake\Console\ConsoleIo $io optional null
The ConsoleIo instance. Used primarily for testing.

Returns

integer
The exit code of the command.

Throws

RuntimeException

setAliases()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

$aliasessource

protected array

Alias mappings.

[]

$appsource

protected Cake\Core\ConsoleApplicationInterface

The application console commands are being run for.

$rootsource

protected string

The root command name. Defaults to cake.

© 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