mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
StringToTParser: added registerAlias()
This commit is contained in:
parent
df96e023dc
commit
20a41b00ba
@ -58,6 +58,21 @@ abstract class StringToTParser{
|
||||
$this->callbackMap[$this->reprocess($alias)] = $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new alias for an existing known alias.
|
||||
*/
|
||||
public function registerAlias(string $existing, string $alias) : void{
|
||||
$existingKey = $this->reprocess($existing);
|
||||
if(!isset($this->callbackMap[$existingKey])){
|
||||
throw new \InvalidArgumentException("Cannot register new alias for unknown existing alias \"$existing\"");
|
||||
}
|
||||
$newKey = $this->reprocess($alias);
|
||||
if(isset($this->callbackMap[$newKey])){
|
||||
throw new \InvalidArgumentException("Alias \"$newKey\" is already registered");
|
||||
}
|
||||
$this->callbackMap[$newKey] = $this->callbackMap[$existingKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to parse the specified string into a corresponding instance of T.
|
||||
* @phpstan-return T|null
|
||||
|
Loading…
x
Reference in New Issue
Block a user