DiscordPHP Documentation

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

Methods

__construct()

public __construct(callable $normalizer) : mixed
Parameters
$normalizer : callable

Normalises a sub-command/alias name (e.g. lower-casing).

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|null

register()

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
string

registerAlias()

Points \`$alias\` at an existing sub-command.

public registerAlias(string $alias, string $command) : void
Parameters
$alias : string
$command : string
Tags
throws
RuntimeException

When the target is unknown, or the alias collides with a sub-command or a different existing alias.

unregister()

Removes a sub-command and any aliases that pointed at it.

public unregister(string $command) : void
Parameters
$command : string
Tags
throws
RuntimeException

When the sub-command does not exist.

unregisterAlias()

Removes a sub-command alias.

public unregisterAlias(string $alias) : void
Parameters
$alias : string
Tags
throws
RuntimeException

When the alias does not exist.

normalize()

Applies the configured normaliser to \`$name\`.

protected normalize(string $name) : string
Parameters
$name : string
Return values
string
On this page

Search results