Class CommandCollection

Collection for Commands.

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

Cake\Console\CommandCollection implements IteratorAggregate, Countable

Properties summary

Method Summary

  • __construct() public
    Constructor
  • add() public
    Add a command to the collection
  • addMany() public
    Add multiple commands at once.
  • Automatically discover shell commands in CakePHP, the application and all plugins.
  • count() public
    Implementation of Countable.
  • get() public
    Get the target for a command.
  • getIterator() public
    Implementation of IteratorAggregate.
  • has() public
    Check whether the named shell exists in the collection.
  • remove() public
    Remove a command from the collection if it exists.

Method Detail

__construct()source public

__construct( array $commands [] )

Constructor

Parameters

array $commands optional []
The map of commands to add to the collection.

add()source public

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

Add a command to the collection

Parameters

string $name
The name of the command you want to map.
string|Cake\Console\Shell $command
The command to map.

Returns


$this

addMany()source public

addMany( array $commands )

Add multiple commands at once.

Parameters

array $commands
A map of command names => command classes/instances.

Returns


$this

See

\Cake\Console\CommandCollection::add()

autoDiscover()source public

autoDiscover( )

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
  • Plugin commands

Commands from plugins will be added based on the order plugins are loaded. Plugin shells will attempt to use a short name. If however, a plugin provides a shell that conflicts with CakePHP or the application shells, the full plugin_name.shell name will be used. Plugin shells are added in the order that plugins were loaded.

Returns

array
An array of command names and their classes.

count()source public

count( )

Implementation of Countable.

Get the number of commands in the collection.

Returns

integer

Implementation of

Countable::count()

get()source public

get( string $name )

Get the target for a command.

Parameters

string $name
The named shell.

Returns

string|Cake\Console\Shell
Either the shell class or an instance.

Throws

InvalidArgumentException
when unknown commands are fetched.

getIterator()source public

getIterator( )

Implementation of IteratorAggregate.

Returns

ArrayIterator

Implementation of

IteratorAggregate::getIterator()

has()source public

has( string $name )

Check whether the named shell exists in the collection.

Parameters

string $name
The named shell.

Returns

boolean

remove()source public

remove( string $name )

Remove a command from the collection if it exists.

Parameters

string $name
The named shell.

Returns


$this

Properties detail

$commandssource

protected array

Command list

[]

© 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.CommandCollection.html