Class CommandCollection
Collection for Commands.
Used by Applications to specify their console commands. CakePHP will use the mapped commands to construct and dispatch shell commands.
Property Summary
- 
        $commands protectedarrayCommand list 
Method Summary
- 
          __construct() publicConstructor 
- 
          add() publicAdd a command to the collection 
- 
          addMany() publicAdd multiple commands at once. 
- 
          autoDiscover() publicAutomatically discover shell commands in CakePHP, the application and all plugins. 
- 
          count() publicImplementation of Countable. 
- 
          discoverPlugin() publicAuto-discover shell & commands from the named plugin. 
- 
          get() publicGet the target for a command. 
- 
          getIterator() publicImplementation of IteratorAggregate. 
- 
          has() publicCheck whether the named shell exists in the collection. 
- 
          keys() publicGet the list of available command names. 
- 
          remove() publicRemove a command from the collection if it exists. 
- 
          resolveNames() protectedResolve names based on existing commands 
Method Detail
__construct() ¶ public
__construct(array $commands = [])Constructor
Parameters
- 
                array$commands optional
- The map of commands to add to the collection. 
add() ¶ public
add(string $name, string|Cake\Console\Shell|Cake\Console\CommandInterface $command): $thisAdd a command to the collection
Parameters
- 
                string$name
- The name of the command you want to map. 
- 
                string|Cake\Console\Shell|Cake\Console\CommandInterface$command
- The command to map. Can be a FQCN, Shell instance or CommandInterface instance. 
Returns
$thisThrows
InvalidArgumentExceptionaddMany() ¶ public
addMany(array $commands): $thisAdd multiple commands at once.
Parameters
- 
                array$commands
- A map of command names => command classes/instances. 
Returns
$thisSee Also
autoDiscover() ¶ public
autoDiscover(): string[]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 overwrite commands with the same name provided by CakePHP.
Returns
string[]An array of command names and their classes.
count() ¶ public
count(): intImplementation of Countable.
Get the number of commands in the collection.
Returns
intdiscoverPlugin() ¶ public
discoverPlugin(string $plugin): string[]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
string[]Discovered plugin commands.
get() ¶ public
get(string $name): string|Cake\Console\Shell|Cake\Console\CommandInterfaceGet the target for a command.
Parameters
- 
                string$name
- The named shell. 
Returns
string|Cake\Console\Shell|Cake\Console\CommandInterfaceEither the command class or an instance.
Throws
InvalidArgumentExceptionwhen unknown commands are fetched.
getIterator() ¶ public
getIterator(): TraversableImplementation of IteratorAggregate.
Returns
Traversablehas() ¶ public
has(string $name): boolCheck whether the named shell exists in the collection.
Parameters
- 
                string$name
- The named shell. 
Returns
boolkeys() ¶ public
keys(): string[]Get the list of available command names.
Returns
string[]Command names
remove() ¶ public
remove(string $name): $thisRemove a command from the collection if it exists.
Parameters
- 
                string$name
- The named shell. 
Returns
$thisresolveNames() ¶ protected
resolveNames(array $input): string[]Resolve names based on existing commands
Parameters
- 
                array$input
- The results of a CommandScanner operation. 
Returns
string[]A flat map of command names => class names.
