Skip to content

Commit

Permalink
Add exception in ImageManager::class when driver could not be resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jan 8, 2025
1 parent 1564e45 commit 72daad8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/ImageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final class ImageManager implements ImageManagerInterface
/**
* @link https://image.intervention.io/v3/basics/image-manager#create-a-new-image-manager-instance
* @param string|DriverInterface $driver
* @throws DriverException
* @param mixed $options
*/
public function __construct(string|DriverInterface $driver, mixed ...$options)
Expand All @@ -32,6 +33,7 @@ public function __construct(string|DriverInterface $driver, mixed ...$options)
* @link https://image.intervention.io/v3/basics/image-manager
* @param string|DriverInterface $driver
* @param mixed $options
* @throws DriverException
* @return ImageManager
*/
public static function withDriver(string|DriverInterface $driver, mixed ...$options): self
Expand Down Expand Up @@ -112,15 +114,24 @@ public function driver(): DriverInterface
}

/**
* Return driver object
* Return driver object from given input which might be driver classname or instance of DriverInterface
*
* @param string|DriverInterface $driver
* @param mixed $options
* @throws DriverException
* @return DriverInterface
*/
private static function resolveDriver(string|DriverInterface $driver, mixed ...$options): DriverInterface
{
$driver = is_string($driver) ? new $driver() : $driver;
$driver = match (true) {
$driver instanceof DriverInterface => $driver,
class_exists($driver) => new $driver(),
default => throw new DriverException(
'Unable to resolve driver. Argment must be either an instance of ' .
DriverInterface::class . '::class or a qualified namespaced name of the driver class.',
),
};

$driver->config()->setOptions(...$options);

return $driver;
Expand Down

0 comments on commit 72daad8

Please sign in to comment.