SubCommandRegistry
in package
Registry for managing sub-commands and their aliases.
Table of Contents
Properties
- $normalizer : callable
- Callable normalizer for command/alias names.
- $subCommandAliases : array<string, string>
- $subCommands : array<string, Command>
Methods
- __construct() : mixed
- all() : array<string, Command>
- Returns all registered sub-commands.
- get() : Command|null
- Resolves \`$command\` (optionally following aliases) to a registered sub-command, or null when it is unknown.
- register() : string
- Register a Command instance and its aliases. Returns the normalized key.
- registerAlias() : void
- Points \`$alias\` at an existing sub-command.
- unregister() : void
- Removes a sub-command and any aliases that pointed at it.
- unregisterAlias() : void
- Removes a sub-command alias.
- normalize() : string
- Applies the configured normaliser to \`$name\`.
Properties
$normalizer
Callable normalizer for command/alias names.
protected
callable
$normalizer
$subCommandAliases
protected
array<string, string>
$subCommandAliases
= []
$subCommands
protected
array<string, Command>
$subCommands
= []
Methods
__construct()
public
__construct(callable $normalizer) : mixed
Parameters
- $normalizer : callable
-
Normalises a sub-command/alias name (e.g. lower-casing).
all()
Returns all registered sub-commands.
public
all() : array<string, Command>
Return values
array<string, Command>get()
Resolves \`$command\` (optionally following aliases) to a registered sub-command, or null when it is unknown.
public
get(string|null $command[, bool $aliases = true ]) : Command|null
Parameters
- $command : string|null
- $aliases : bool = true
Return values
Command|nullregister()
Register a Command instance and its aliases. Returns the normalized key.
public
register(Command $commandInstance[, array<string|int, mixed> $aliases = [] ]) : string
Parameters
- $commandInstance : Command
- $aliases : array<string|int, mixed> = []
Return values
stringregisterAlias()
Points \`$alias\` at an existing sub-command.
public
registerAlias(string $alias, string $command) : void
Parameters
- $alias : string
- $command : string
Tags
unregister()
Removes a sub-command and any aliases that pointed at it.
public
unregister(string $command) : void
Parameters
- $command : string
Tags
unregisterAlias()
Removes a sub-command alias.
public
unregisterAlias(string $alias) : void
Parameters
- $alias : string
Tags
normalize()
Applies the configured normaliser to \`$name\`.
protected
normalize(string $name) : string
Parameters
- $name : string