1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-21 05:01:20 +02:00

Accept only driver classes which implement DriverInterface

This commit is contained in:
Oliver Vogel
2025-01-26 10:58:51 +01:00
parent 9f26854faf
commit f6165cda94

View File

@@ -9,6 +9,7 @@ use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Drivers\Gd\Driver as GdDriver; use Intervention\Image\Drivers\Gd\Driver as GdDriver;
use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver; use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver;
use Intervention\Image\Exceptions\DriverException; use Intervention\Image\Exceptions\DriverException;
use Intervention\Image\Exceptions\InputException;
use Intervention\Image\Interfaces\DecoderInterface; use Intervention\Image\Interfaces\DecoderInterface;
use Intervention\Image\Interfaces\ImageManagerInterface; use Intervention\Image\Interfaces\ImageManagerInterface;
@@ -20,6 +21,7 @@ final class ImageManager implements ImageManagerInterface
* @link https://image.intervention.io/v3/basics/image-manager#create-a-new-image-manager-instance * @link https://image.intervention.io/v3/basics/image-manager#create-a-new-image-manager-instance
* @param string|DriverInterface $driver * @param string|DriverInterface $driver
* @throws DriverException * @throws DriverException
* @throws InputException
* @param mixed $options * @param mixed $options
*/ */
public function __construct(string|DriverInterface $driver, mixed ...$options) public function __construct(string|DriverInterface $driver, mixed ...$options)
@@ -34,6 +36,7 @@ final class ImageManager implements ImageManagerInterface
* @param string|DriverInterface $driver * @param string|DriverInterface $driver
* @param mixed $options * @param mixed $options
* @throws DriverException * @throws DriverException
* @throws InputException
* @return ImageManager * @return ImageManager
*/ */
public static function withDriver(string|DriverInterface $driver, mixed ...$options): self public static function withDriver(string|DriverInterface $driver, mixed ...$options): self
@@ -47,6 +50,7 @@ final class ImageManager implements ImageManagerInterface
* @link https://image.intervention.io/v3/basics/image-manager#static-gd-driver-constructor * @link https://image.intervention.io/v3/basics/image-manager#static-gd-driver-constructor
* @param mixed $options * @param mixed $options
* @throws DriverException * @throws DriverException
* @throws InputException
* @return ImageManager * @return ImageManager
*/ */
public static function gd(mixed ...$options): self public static function gd(mixed ...$options): self
@@ -60,6 +64,7 @@ final class ImageManager implements ImageManagerInterface
* @link https://image.intervention.io/v3/basics/image-manager#static-imagick-driver-constructor * @link https://image.intervention.io/v3/basics/image-manager#static-imagick-driver-constructor
* @param mixed $options * @param mixed $options
* @throws DriverException * @throws DriverException
* @throws InputException
* @return ImageManager * @return ImageManager
*/ */
public static function imagick(mixed ...$options): self public static function imagick(mixed ...$options): self
@@ -119,6 +124,7 @@ final class ImageManager implements ImageManagerInterface
* @param string|DriverInterface $driver * @param string|DriverInterface $driver
* @param mixed $options * @param mixed $options
* @throws DriverException * @throws DriverException
* @throws InputException
* @return DriverInterface * @return DriverInterface
*/ */
private static function resolveDriver(string|DriverInterface $driver, mixed ...$options): DriverInterface private static function resolveDriver(string|DriverInterface $driver, mixed ...$options): DriverInterface
@@ -132,6 +138,12 @@ final class ImageManager implements ImageManagerInterface
), ),
}; };
if (!$driver instanceof DriverInterface) {
throw new DriverException(
'Unable to resolve driver. Driver object must implement ' . DriverInterface::class . '.',
);
}
$driver->config()->setOptions(...$options); $driver->config()->setOptions(...$options);
return $driver; return $driver;