\Cake\ConsoleCommandCollection

Collection for Commands.

Used by Applications to whitelist their console commands. CakePHP will use the mapped commands to construct and dispatch shell commands.

Summary

Methods
Properties
Constants
__construct()
add()
addMany()
remove()
has()
get()
getIterator()
count()
discoverPlugin()
autoDiscover()
No public properties found
No constants found
resolveNames()
$commands
N/A
No private methods found
No private properties found
N/A

Properties

$commands

$commands : array

Command list

Type

array

Methods

__construct()

__construct(array  $commands = array()) 

Constructor

Parameters

array $commands

The map of commands to add to the collection.

add()

add(string  $name, string|\Cake\Console\Shell|\Cake\Console\Command  $command) : $this

Add a command to the collection

Parameters

string $name

The name of the command you want to map.

string|\Cake\Console\Shell|\Cake\Console\Command $command

The command to map.

Returns

$this

addMany()

addMany(array  $commands) : $this

Add multiple commands at once.

Parameters

array $commands

A map of command names => command classes/instances.

Returns

$this

remove()

remove(string  $name) : $this

Remove a command from the collection if it exists.

Parameters

string $name

The named shell.

Returns

$this

has()

has(string  $name) : boolean

Check whether the named shell exists in the collection.

Parameters

string $name

The named shell.

Returns

boolean

get()

get(string  $name) : string|\Cake\Console\Shell

Get the target for a command.

Parameters

string $name

The named shell.

Throws

\InvalidArgumentException

when unknown commands are fetched.

Returns

string|\Cake\Console\Shell

Either the shell class or an instance.

getIterator()

getIterator() : \ArrayIterator

Implementation of IteratorAggregate.

Returns

\ArrayIterator

count()

count() : integer

Implementation of Countable.

Get the number of commands in the collection.

Returns

integer

discoverPlugin()

discoverPlugin(string  $plugin) : array

Auto-discover shell & commands from the named plugin.

Discovered commands will have their names de-duplicated with existing commands in the collection. If a command is already defined in the collection and discovered in a plugin, only the long name (plugin.command) will be returned.

Parameters

string $plugin

The plugin to scan.

Returns

array —

Discovered plugin commands.

autoDiscover()

autoDiscover() : array

Automatically discover shell commands in CakePHP, the application and all plugins.

Commands will be located using filesystem conventions. Commands are discovered in the following order:

  • CakePHP provided commands
  • Application commands

Commands defined in the application will ovewrite commands with the same name provided by CakePHP.

Returns

array —

An array of command names and their classes.

resolveNames()

resolveNames(array  $input) : array

Resolve names based on existing commands

Parameters

array $input

The results of a CommandScanner operation.

Returns

array —

A flat map of command names => class names.