1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-30 09:10:21 +02:00

allow intervention to use own drivers

This commit is contained in:
Frederik Bosch
2017-01-18 20:35:45 +01:00
parent 2bce9a59c4
commit 9729f0ef21
2 changed files with 26 additions and 5 deletions

View File

@@ -100,6 +100,7 @@ class ImageManager
*/ */
private function createDriver() private function createDriver()
{ {
if (is_string($this->config['driver'])) {
$drivername = ucfirst($this->config['driver']); $drivername = ucfirst($this->config['driver']);
$driverclass = sprintf('Intervention\\Image\\%s\\Driver', $drivername); $driverclass = sprintf('Intervention\\Image\\%s\\Driver', $drivername);
@@ -112,6 +113,15 @@ class ImageManager
); );
} }
if ($this->config['driver'] instanceof AbstractDriver) {
return $this->config['driver'];
}
throw new \Intervention\Image\Exception\NotSupportedException(
"Unknown driver type."
);
}
/** /**
* Check if all requirements are available * Check if all requirements are available
* *

View File

@@ -1,5 +1,6 @@
<?php <?php
use Intervention\Image\Image;
use Intervention\Image\ImageManager; use Intervention\Image\ImageManager;
class ImageManagerTest extends PHPUnit_Framework_TestCase class ImageManagerTest extends PHPUnit_Framework_TestCase
@@ -26,4 +27,14 @@ class ImageManagerTest extends PHPUnit_Framework_TestCase
$this->assertEquals('foo', $manager->config['driver']); $this->assertEquals('foo', $manager->config['driver']);
$this->assertEquals('baz', $manager->config['bar']); $this->assertEquals('baz', $manager->config['bar']);
} }
public function testConfigureObject()
{
$config = array('driver' => new Intervention\Image\Imagick\Driver());
$manager = new ImageManager($config);
$image = $manager->make('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7');
$this->assertInstanceOf(Image::class, $image);
$this->assertInstanceOf(Imagick::class, $image->getCore());
}
} }