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 protected
array<string,Cake\Console\CommandInterface|class-stringCake\Console\CommandInterface>>
Command list
Method Summary
-
__construct() public
Constructor
-
add() public
Add a command to the collection
-
addMany() public
Add multiple commands at once.
-
autoDiscover() public
Automatically discover commands in CakePHP, the application and all plugins.
-
count() public
Implementation of Countable.
-
discoverPlugin() public
Auto-discover commands from the named plugin.
-
get() public
Get the target for a command.
-
getIterator() public
Implementation of IteratorAggregate.
-
has() public
Check whether the named shell exists in the collection.
-
keys() public
Get the list of available command names.
-
remove() public
Remove a command from the collection if it exists.
-
resolveNames() protected
Resolve names based on existing commands
Method Detail
__construct() ¶ public
__construct(array<string,Cake\Console\CommandInterface|class-stringCake\Console\CommandInterface>> $commands = [])
Constructor
Parameters
-
array<string,Cake\Console\CommandInterface|class-stringCake\Console\CommandInterface>>
$commands optional The map of commands to add to the collection.
add() ¶ public
add(string $name, Cake\Console\CommandInterface|class-stringCake\Console\CommandInterface> $command): $this
Add a command to the collection
Parameters
-
string
$name The name of the command you want to map.
-
Cake\Console\CommandInterface|class-stringCake\Console\CommandInterface>
$command The command to map. Can be a FQCN or CommandInterface instance.
Returns
$this
Throws
InvalidArgumentException
addMany() ¶ public
addMany(array<string,Cake\Console\CommandInterface|class-stringCake\Console\CommandInterface>> $commands): $this
Add multiple commands at once.
Parameters
-
array<string,Cake\Console\CommandInterface|class-stringCake\Console\CommandInterface>>
$commands A map of command names => command classes/instances.
Returns
$this
See Also
autoDiscover() ¶ public
autoDiscover(): array<string, class-stringCake\Console\CommandInterface>>
Automatically discover 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
array<string, class-stringCake\Console\CommandInterface>>
count() ¶ public
count(): int
Implementation of Countable.
Get the number of commands in the collection.
Returns
int
discoverPlugin() ¶ public
discoverPlugin(string $plugin): array<string, class-stringCake\Console\CommandInterface>>
Auto-discover 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<string, class-stringCake\Console\CommandInterface>>
get() ¶ public
get(string $name): Cake\Console\CommandInterface|class-stringCake\Console\CommandInterface>
Get the target for a command.
Parameters
-
string
$name The named shell.
Returns
Cake\Console\CommandInterface|class-stringCake\Console\CommandInterface>
Throws
InvalidArgumentException
when unknown commands are fetched.
getIterator() ¶ public
getIterator(): Traversable
Implementation of IteratorAggregate.
Returns
Traversable
has() ¶ public
has(string $name): bool
Check whether the named shell exists in the collection.
Parameters
-
string
$name The named shell.
Returns
bool
remove() ¶ public
remove(string $name): $this
Remove a command from the collection if it exists.
Parameters
-
string
$name The named shell.
Returns
$this
resolveNames() ¶ protected
resolveNames(array<array<string, string>> $input): array<string, class-stringCake\Console\CommandInterface>>
Resolve names based on existing commands
Parameters
-
array<array<string, string>>
$input The results of a CommandScanner operation.
Returns
array<string, class-stringCake\Console\CommandInterface>>
Property Detail
$commands ¶ protected
Command list
Type
array<string,Cake\Console\CommandInterface|class-stringCake\Console\CommandInterface>>