Skip to content

Commit

Permalink
Accept only driver classes which implement DriverInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jan 26, 2025
1 parent 9f26854 commit f6165cd
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ImageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Intervention\Image\Drivers\Gd\Driver as GdDriver;
use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver;
use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Exceptions\InputException;
use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageManagerInterface;

Expand All @@ -20,6 +21,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
* @throws InputException
* @param mixed $options
*/
public function __construct(string|DriverInterface $driver, mixed ...$options)
Expand All @@ -34,6 +36,7 @@ public function __construct(string|DriverInterface $driver, mixed ...$options)
* @param string|DriverInterface $driver
* @param mixed $options
* @throws DriverException
* @throws InputException
* @return ImageManager
*/
public static function withDriver(string|DriverInterface $driver, mixed ...$options): self
Expand All @@ -47,6 +50,7 @@ public static function withDriver(string|DriverInterface $driver, mixed ...$opti
* @link https://image.intervention.io/v3/basics/image-manager#static-gd-driver-constructor
* @param mixed $options
* @throws DriverException
* @throws InputException
* @return ImageManager
*/
public static function gd(mixed ...$options): self
Expand All @@ -60,6 +64,7 @@ public static function gd(mixed ...$options): self
* @link https://image.intervention.io/v3/basics/image-manager#static-imagick-driver-constructor
* @param mixed $options
* @throws DriverException
* @throws InputException
* @return ImageManager
*/
public static function imagick(mixed ...$options): self
Expand Down Expand Up @@ -119,6 +124,7 @@ public function driver(): DriverInterface
* @param string|DriverInterface $driver
* @param mixed $options
* @throws DriverException
* @throws InputException
* @return DriverInterface
*/
private static function resolveDriver(string|DriverInterface $driver, mixed ...$options): DriverInterface
Expand All @@ -132,6 +138,12 @@ class_exists($driver) => new $driver(),
),
};

if (!$driver instanceof DriverInterface) {
throw new DriverException(
'Unable to resolve driver. Driver object must implement ' . DriverInterface::class . '.',
);
}

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

return $driver;
Expand Down

0 comments on commit f6165cd

Please sign in to comment.