mirror of
https://github.com/Intervention/image.git
synced 2025-08-31 01:29:51 +02:00
Perform dependency check on driver creation
This commit is contained in:
@@ -11,6 +11,11 @@ use ReflectionClass;
|
||||
|
||||
abstract class AbstractDriver implements DriverInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->checkHealth();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a specialized version for the current driver of the given object
|
||||
*
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace Intervention\Image\Drivers\Gd;
|
||||
|
||||
use Intervention\Image\Drivers\AbstractDriver;
|
||||
use Intervention\Image\Exceptions\RuntimeException;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\ColorProcessorInterface;
|
||||
@@ -22,6 +23,20 @@ class Driver extends AbstractDriver
|
||||
return 'GD';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see DriverInterface::checkHealth()
|
||||
*/
|
||||
public function checkHealth(): void
|
||||
{
|
||||
if (!extension_loaded('gd') || !function_exists('gd_info')) {
|
||||
throw new RuntimeException(
|
||||
'GD Library extension not available with this PHP installation.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
|
@@ -5,6 +5,7 @@ namespace Intervention\Image\Drivers\Imagick;
|
||||
use Imagick;
|
||||
use ImagickPixel;
|
||||
use Intervention\Image\Drivers\AbstractDriver;
|
||||
use Intervention\Image\Exceptions\RuntimeException;
|
||||
use Intervention\Image\Image;
|
||||
use Intervention\Image\Interfaces\ColorInterface;
|
||||
use Intervention\Image\Interfaces\ColorProcessorInterface;
|
||||
@@ -24,6 +25,20 @@ class Driver extends AbstractDriver
|
||||
return 'Imagick';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see DriverInterface::checkHealth()
|
||||
*/
|
||||
public function checkHealth(): void
|
||||
{
|
||||
if (!extension_loaded('imagick') || !class_exists('Imagick')) {
|
||||
throw new RuntimeException(
|
||||
'ImageMagick extension not available with this PHP installation.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
|
@@ -51,4 +51,11 @@ interface DriverInterface
|
||||
* @return ColorProcessorInterface
|
||||
*/
|
||||
public function colorProcessor(ColorspaceInterface $colorspace): ColorProcessorInterface;
|
||||
|
||||
/**
|
||||
* Check whether all requirements for operating the driver are met
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function checkHealth(): void;
|
||||
}
|
||||
|
Reference in New Issue
Block a user