From faf71b8faeccfe8a549c92ab14829a404e8c88a2 Mon Sep 17 00:00:00 2001 From: Ollie Read Date: Mon, 16 Dec 2024 12:00:34 +0000 Subject: [PATCH] fix: Fix bug with custom creators --- src/Support/BaseFactory.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Support/BaseFactory.php b/src/Support/BaseFactory.php index d2dd4e2..448ec2e 100644 --- a/src/Support/BaseFactory.php +++ b/src/Support/BaseFactory.php @@ -186,15 +186,22 @@ protected function resolve(string $name): object } // Ooo custom creation logic, let's use that - if (isset($this->customCreators[$name])) { + if (isset(static::$customCreators[$name])) { return $this->callCustomCreator($name, $config); } + /** @var string|null $driver */ + $driver = $config['driver'] ?? null; + // Is there a driver? - if (isset($config['driver'])) { + if ($driver !== null) { + // Is there a custom creator for the driver? + if (isset(static::$customCreators[$driver])) { + return $this->callCustomCreator($driver, $config); + } + // This has a driver, so we'll see if we can create based on that - /** @phpstan-ignore-next-line */ - $method = 'create' . ucfirst($config['driver']) . ucfirst($this->getFactoryName()); + $method = 'create' . ucfirst($driver) . ucfirst($this->getFactoryName()); } else { // There's no driver, so we'll see if there's a default available $method = 'createDefault' . ucfirst($this->getFactoryName());