Fr3nch13/CakePHP Utilities

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
psalm-var

array<string, \Cake\Console\Shell|\Cake\Console\CommandInterface|class-string>

psalm-suppress

DeprecatedClass

Methods

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
throws
InvalidArgumentException
Return values
$this

autoDiscover()

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
int

discoverPlugin()

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
throws
InvalidArgumentException

when unknown commands are fetched.

psalm-return

\Cake\Console\CommandInterface|\Cake\Console\Shell|class-string

Return values
CommandInterface|Shell|string

Either the command class or an instance.

getIterator()

Implementation of IteratorAggregate.

public getIterator() : Traversable
Tags
psalm-return

\Traversable<string, \Cake\Console\Shell|\Cake\Console\CommandInterface|class-string>

Return values
Traversable

has()

Check whether the named shell exists in the collection.

public has(string $name) : bool
Parameters
$name : string

The named shell.

Return values
bool

keys()

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
$this

resolveNames()

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.


        
On this page

Search results