mirror of
https://github.com/Intervention/image.git
synced 2025-09-01 01:51:43 +02:00
Perform dependency check on driver creation
This commit is contained in:
@@ -11,6 +11,11 @@ use ReflectionClass;
|
|||||||
|
|
||||||
abstract class AbstractDriver implements DriverInterface
|
abstract class AbstractDriver implements DriverInterface
|
||||||
{
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->checkHealth();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a specialized version for the current driver of the given object
|
* Return a specialized version for the current driver of the given object
|
||||||
*
|
*
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
namespace Intervention\Image\Drivers\Gd;
|
namespace Intervention\Image\Drivers\Gd;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\AbstractDriver;
|
use Intervention\Image\Drivers\AbstractDriver;
|
||||||
|
use Intervention\Image\Exceptions\RuntimeException;
|
||||||
use Intervention\Image\Image;
|
use Intervention\Image\Image;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\ColorProcessorInterface;
|
use Intervention\Image\Interfaces\ColorProcessorInterface;
|
||||||
@@ -22,6 +23,20 @@ class Driver extends AbstractDriver
|
|||||||
return 'GD';
|
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}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
|
@@ -5,6 +5,7 @@ namespace Intervention\Image\Drivers\Imagick;
|
|||||||
use Imagick;
|
use Imagick;
|
||||||
use ImagickPixel;
|
use ImagickPixel;
|
||||||
use Intervention\Image\Drivers\AbstractDriver;
|
use Intervention\Image\Drivers\AbstractDriver;
|
||||||
|
use Intervention\Image\Exceptions\RuntimeException;
|
||||||
use Intervention\Image\Image;
|
use Intervention\Image\Image;
|
||||||
use Intervention\Image\Interfaces\ColorInterface;
|
use Intervention\Image\Interfaces\ColorInterface;
|
||||||
use Intervention\Image\Interfaces\ColorProcessorInterface;
|
use Intervention\Image\Interfaces\ColorProcessorInterface;
|
||||||
@@ -24,6 +25,20 @@ class Driver extends AbstractDriver
|
|||||||
return 'Imagick';
|
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}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
|
@@ -51,4 +51,11 @@ interface DriverInterface
|
|||||||
* @return ColorProcessorInterface
|
* @return ColorProcessorInterface
|
||||||
*/
|
*/
|
||||||
public function colorProcessor(ColorspaceInterface $colorspace): 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