From 25dde40126aa2026e1c781e502911cdd8dc4030f Mon Sep 17 00:00:00 2001 From: Randall Wilk Date: Wed, 6 Mar 2024 11:08:12 -0600 Subject: [PATCH] Change how custom generators are resolved --- src/Support/GeneratorFactory.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Support/GeneratorFactory.php b/src/Support/GeneratorFactory.php index 6c6a673..c10ad40 100644 --- a/src/Support/GeneratorFactory.php +++ b/src/Support/GeneratorFactory.php @@ -23,15 +23,21 @@ public static function make(string $generator): self public function generator(): Generator { - if (class_exists($this->generator) && in_array(Generator::class, class_implements($this->generator), true)) { - return new $this->generator; - } - return match ($this->generator) { 'ksuid' => new KsuidGenerator, 'snowflake' => new SnowflakeGenerator, 'uuid' => new UuidGenerator, - default => throw InvalidGenerator::invalid($this->generator), + default => $this->makeCustomGenerator($this->generator), }; } + + protected function makeCustomGenerator(string $generator): Generator + { + throw_unless( + class_exists($generator) && in_array(Generator::class, class_implements($generator), true), + InvalidGenerator::invalid($generator) + ); + + return new $generator; + } }