CommandRegistry
in package
Registry for message command client commands and aliases.
Tags
Table of Contents
Properties
- $aliases : array<string, string>
- Map of alias => command name.
- $caseInsensitive : bool
- Whether command names/aliases should be treated case-insensitively.
- $commands : array<string, Command>
- Map of command name => Command instance.
Methods
- __construct() : mixed
- Creates a command registry instance.
- add() : void
- Add a command to the registry.
- addAlias() : void
- Add an alias for an existing command name.
- aliases() : array<string, string>
- Return all registered aliases.
- all() : array<string, Command>
- Return all registered commands.
- get() : Command|null
- Retrieve a command by name or alias.
- has() : bool
- Check whether a command or alias exists.
- hasAlias() : bool
- Check whether an alias exists.
- hasCommand() : bool
- Check whether a command exists.
- remove() : void
- Remove a command from the registry.
- removeAlias() : void
- Remove an alias.
- normalize() : string
- Normalize a command/alias name according to the case sensitivity setting.
Properties
$aliases
Map of alias => command name.
protected
array<string, string>
$aliases
= []
$caseInsensitive
Whether command names/aliases should be treated case-insensitively.
protected
bool
$caseInsensitive
$commands
Map of command name => Command instance.
protected
array<string, Command>
$commands
= []
Methods
__construct()
Creates a command registry instance.
public
__construct([bool $caseInsensitive = false ]) : mixed
Parameters
- $caseInsensitive : bool = false
-
Whether command names/aliases should be treated case-insensitively.
add()
Add a command to the registry.
public
add(string $name, Command $command) : void
Parameters
- $name : string
-
Command trigger name.
- $command : Command
-
Command instance.
Tags
addAlias()
Add an alias for an existing command name.
public
addAlias(string $alias, string $commandName) : void
Parameters
- $alias : string
-
Alias name.
- $commandName : string
-
Target command name.
aliases()
Return all registered aliases.
public
aliases() : array<string, string>
Return values
array<string, string>all()
Return all registered commands.
public
all() : array<string, Command>
Return values
array<string, Command>get()
Retrieve a command by name or alias.
public
get(string $name) : Command|null
Parameters
- $name : string
-
Command name or alias.
Return values
Command|null —The command instance or null if not found.
has()
Check whether a command or alias exists.
public
has(string $name) : bool
Parameters
- $name : string
-
Command or alias to check.
Return values
boolhasAlias()
Check whether an alias exists.
public
hasAlias(string $alias) : bool
Parameters
- $alias : string
-
Alias to check.
Return values
boolhasCommand()
Check whether a command exists.
public
hasCommand(string $name) : bool
Parameters
- $name : string
-
Command name to check.
Return values
boolremove()
Remove a command from the registry.
public
remove(string $name) : void
This does not remove any aliases pointing to this command, so they will become invalid until removed or updated.
Parameters
- $name : string
-
Command trigger name.
removeAlias()
Remove an alias.
public
removeAlias(string $alias) : void
Parameters
- $alias : string
-
Alias to remove.
normalize()
Normalize a command/alias name according to the case sensitivity setting.
protected
normalize(string $name) : string
Parameters
- $name : string