CommandCollection
in package
implements
IteratorAggregate, Countable
Collection for Commands.
Used by Applications to specify their console commands. CakePHP will use the mapped commands to construct and dispatch shell commands.
Table of Contents
Interfaces
- IteratorAggregate
- Countable
Properties
- $commands : array<string, Shell|CommandInterface|string>
- Command list
Methods
- __construct() : mixed
- Constructor
- add() : $this
- Add a command to the collection
- addMany() : $this
- Add multiple commands at once.
- autoDiscover() : array<string, string>
- Automatically discover shell commands in CakePHP, the application and all plugins.
- count() : int
- Implementation of Countable.
- discoverPlugin() : array<string, string>
- Auto-discover shell & commands from the named plugin.
- get() : CommandInterface|Shell|string
- Get the target for a command.
- getIterator() : Traversable
- Implementation of IteratorAggregate.
- has() : bool
- Check whether the named shell exists in the collection.
- keys() : array<string|int, string>
- Get the list of available command names.
- remove() : $this
- Remove a command from the collection if it exists.
- resolveNames() : array<string, string>
- Resolve names based on existing commands
Properties
$commands
Command list
protected
array<string, Shell|CommandInterface|string>
$commands
= []
Tags
Methods
__construct()
Constructor
public
__construct([array<string, Shell|CommandInterface|string> $commands = [] ]) : mixed
Parameters
- $commands : array<string, Shell|CommandInterface|string> = []
-
The map of commands to add to the collection.
add()
Add a command to the collection
public
add(string $name, CommandInterface|Shell|string $command) : $this
Parameters
- $name : string
-
The name of the command you want to map.
- $command : CommandInterface|Shell|string
-
The command to map. Can be a FQCN, Shell instance or CommandInterface instance.
Tags
Return values
$thisaddMany()
Add multiple commands at once.
public
addMany(array<string, Shell|CommandInterface|string> $commands) : $this
Parameters
- $commands : array<string, Shell|CommandInterface|string>
-
A map of command names => command classes/instances.
Tags
Return values
$thisautoDiscover()
Automatically discover shell commands in CakePHP, the application and all plugins.
public
autoDiscover() : array<string, string>
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.
Return values
array<string, string> —An array of command names and their classes.
count()
Implementation of Countable.
public
count() : int
Get the number of commands in the collection.
Return values
intdiscoverPlugin()
Auto-discover shell & commands from the named plugin.
public
discoverPlugin(string $plugin) : array<string, string>
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
- $plugin : string
-
The plugin to scan.
Return values
array<string, string> —Discovered plugin commands.
get()
Get the target for a command.
public
get(string $name) : CommandInterface|Shell|string
Parameters
- $name : string
-
The named shell.
Tags
Return values
CommandInterface|Shell|string —Either the command class or an instance.
getIterator()
Implementation of IteratorAggregate.
public
getIterator() : Traversable
Tags
Return values
Traversablehas()
Check whether the named shell exists in the collection.
public
has(string $name) : bool
Parameters
- $name : string
-
The named shell.
Return values
boolkeys()
Get the list of available command names.
public
keys() : array<string|int, string>
Return values
array<string|int, string> —Command names
remove()
Remove a command from the collection if it exists.
public
remove(string $name) : $this
Parameters
- $name : string
-
The named shell.
Return values
$thisresolveNames()
Resolve names based on existing commands
protected
resolveNames(array<string|int, mixed> $input) : array<string, string>
Parameters
- $input : array<string|int, mixed>
-
The results of a CommandScanner operation.
Return values
array<string, string> —A flat map of command names => class names.