Skip to content

Commit f6165cd

Browse files
committed
Accept only driver classes which implement DriverInterface
1 parent 9f26854 commit f6165cd

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/ImageManager.php

+12
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Intervention\Image\Drivers\Gd\Driver as GdDriver;
1010
use Intervention\Image\Drivers\Imagick\Driver as ImagickDriver;
1111
use Intervention\Image\Exceptions\DriverException;
12+
use Intervention\Image\Exceptions\InputException;
1213
use Intervention\Image\Interfaces\DecoderInterface;
1314
use Intervention\Image\Interfaces\ImageManagerInterface;
1415

@@ -20,6 +21,7 @@ final class ImageManager implements ImageManagerInterface
2021
* @link https://image.intervention.io/v3/basics/image-manager#create-a-new-image-manager-instance
2122
* @param string|DriverInterface $driver
2223
* @throws DriverException
24+
* @throws InputException
2325
* @param mixed $options
2426
*/
2527
public function __construct(string|DriverInterface $driver, mixed ...$options)
@@ -34,6 +36,7 @@ public function __construct(string|DriverInterface $driver, mixed ...$options)
3436
* @param string|DriverInterface $driver
3537
* @param mixed $options
3638
* @throws DriverException
39+
* @throws InputException
3740
* @return ImageManager
3841
*/
3942
public static function withDriver(string|DriverInterface $driver, mixed ...$options): self
@@ -47,6 +50,7 @@ public static function withDriver(string|DriverInterface $driver, mixed ...$opti
4750
* @link https://image.intervention.io/v3/basics/image-manager#static-gd-driver-constructor
4851
* @param mixed $options
4952
* @throws DriverException
53+
* @throws InputException
5054
* @return ImageManager
5155
*/
5256
public static function gd(mixed ...$options): self
@@ -60,6 +64,7 @@ public static function gd(mixed ...$options): self
6064
* @link https://image.intervention.io/v3/basics/image-manager#static-imagick-driver-constructor
6165
* @param mixed $options
6266
* @throws DriverException
67+
* @throws InputException
6368
* @return ImageManager
6469
*/
6570
public static function imagick(mixed ...$options): self
@@ -119,6 +124,7 @@ public function driver(): DriverInterface
119124
* @param string|DriverInterface $driver
120125
* @param mixed $options
121126
* @throws DriverException
127+
* @throws InputException
122128
* @return DriverInterface
123129
*/
124130
private static function resolveDriver(string|DriverInterface $driver, mixed ...$options): DriverInterface
@@ -132,6 +138,12 @@ class_exists($driver) => new $driver(),
132138
),
133139
};
134140

141+
if (!$driver instanceof DriverInterface) {
142+
throw new DriverException(
143+
'Unable to resolve driver. Driver object must implement ' . DriverInterface::class . '.',
144+
);
145+
}
146+
135147
$driver->config()->setOptions(...$options);
136148

137149
return $driver;

0 commit comments

Comments
 (0)