1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-14 09:54:13 +02:00

added coreAvailable() method to drivers

This commit is contained in:
Oliver Vogel
2014-05-18 16:33:01 +02:00
parent ef57a497c1
commit 27989001ee
3 changed files with 39 additions and 0 deletions

View File

@@ -36,6 +36,13 @@ abstract class AbstractDriver
*/ */
abstract public function parseColor($value); abstract public function parseColor($value);
/**
* Checks if core module installation is available
*
* @return boolean
*/
abstract protected function coreAvailable();
/** /**
* Initiates new image from given input * Initiates new image from given input
* *

View File

@@ -14,6 +14,12 @@ class Driver extends \Intervention\Image\AbstractDriver
*/ */
public function __construct(Source $source = null, Encoder $encoder = null) public function __construct(Source $source = null, Encoder $encoder = null)
{ {
if ( ! $this->coreAvailable()) {
throw new \Intervention\Image\Exception\NotSupportedException(
"GD Library extension not available with this PHP installation."
);
}
$this->source = $source ? $source : new Source; $this->source = $source ? $source : new Source;
$this->encoder = $encoder ? $encoder : new Encoder; $this->encoder = $encoder ? $encoder : new Encoder;
} }
@@ -50,4 +56,14 @@ class Driver extends \Intervention\Image\AbstractDriver
{ {
return new Color($value); return new Color($value);
} }
/**
* Checks if core module installation is available
*
* @return boolean
*/
protected function coreAvailable()
{
return (extension_loaded('gd') && function_exists('gd_info'));
}
} }

View File

@@ -14,6 +14,12 @@ class Driver extends \Intervention\Image\AbstractDriver
*/ */
public function __construct(Source $source = null, Encoder $encoder = null) public function __construct(Source $source = null, Encoder $encoder = null)
{ {
if ( ! $this->coreAvailable()) {
throw new \Intervention\Image\Exception\NotSupportedException(
"ImageMagick module not available with this PHP installation."
);
}
$this->source = $source ? $source : new Source; $this->source = $source ? $source : new Source;
$this->encoder = $encoder ? $encoder : new Encoder; $this->encoder = $encoder ? $encoder : new Encoder;
} }
@@ -56,4 +62,14 @@ class Driver extends \Intervention\Image\AbstractDriver
{ {
return new Color($value); return new Color($value);
} }
/**
* Checks if core module installation is available
*
* @return boolean
*/
protected function coreAvailable()
{
return (extension_loaded('imagick') && class_exists('Imagick'));
}
} }