GeneratorManager::getGenerator() now returns null for unknown generator aliases

instead of returning Normal::class (indistinguishable from successful match) or throwing an exception (pain in the ass to handle).
This commit is contained in:
Dylan K. Taylor
2021-10-11 16:04:36 +01:00
parent e62794e4cf
commit 7b6632941d
5 changed files with 15 additions and 20 deletions

View File

@ -79,20 +79,11 @@ final class GeneratorManager{
*
* @param bool $throwOnMissing @deprecated this is for backwards compatibility only
*
* @return string Name of class that extends Generator
* @phpstan-return class-string<Generator>
*
* @throws \InvalidArgumentException if the generator type isn't registered
* @return string|null Name of class that extends Generator, or null if no generator is mapped to that name
* @phpstan-return class-string<Generator>|null
*/
public function getGenerator(string $name, bool $throwOnMissing = false){
if(isset($this->list[$name = strtolower($name)])){
return $this->list[$name];
}
if($throwOnMissing){
throw new \InvalidArgumentException("Alias \"$name\" does not map to any known generator");
}
return Normal::class;
public function getGenerator(string $name, bool $throwOnMissing = false) : ?string{
return $this->list[strtolower($name)] ?? null;
}
/**