diff --git a/src/utils/StringToTParser.php b/src/utils/StringToTParser.php index 0166e2a28..d98153ac1 100644 --- a/src/utils/StringToTParser.php +++ b/src/utils/StringToTParser.php @@ -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