From 9729f0ef21523c17e04afea4771c4ff2a69dd5ed Mon Sep 17 00:00:00 2001 From: Frederik Bosch Date: Wed, 18 Jan 2017 20:35:45 +0100 Subject: [PATCH 1/2] allow intervention to use own drivers --- src/Intervention/Image/ImageManager.php | 20 +++++++++++++++----- tests/ImageManagerTest.php | 11 +++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Intervention/Image/ImageManager.php b/src/Intervention/Image/ImageManager.php index a5df0540..205d17f0 100644 --- a/src/Intervention/Image/ImageManager.php +++ b/src/Intervention/Image/ImageManager.php @@ -100,15 +100,25 @@ class ImageManager */ private function createDriver() { - $drivername = ucfirst($this->config['driver']); - $driverclass = sprintf('Intervention\\Image\\%s\\Driver', $drivername); + if (is_string($this->config['driver'])) { + $drivername = ucfirst($this->config['driver']); + $driverclass = sprintf('Intervention\\Image\\%s\\Driver', $drivername); - if (class_exists($driverclass)) { - return new $driverclass; + if (class_exists($driverclass)) { + return new $driverclass; + } + + throw new \Intervention\Image\Exception\NotSupportedException( + "Driver ({$drivername}) could not be instantiated." + ); + } + + if ($this->config['driver'] instanceof AbstractDriver) { + return $this->config['driver']; } throw new \Intervention\Image\Exception\NotSupportedException( - "Driver ({$drivername}) could not be instantiated." + "Unknown driver type." ); } diff --git a/tests/ImageManagerTest.php b/tests/ImageManagerTest.php index d28d0c4c..7f0a78c3 100644 --- a/tests/ImageManagerTest.php +++ b/tests/ImageManagerTest.php @@ -1,5 +1,6 @@ assertEquals('foo', $manager->config['driver']); $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()); + } } From b27bbe5771e471b24445884a29fd7e9498fae07e Mon Sep 17 00:00:00 2001 From: Frederik Bosch Date: Wed, 18 Jan 2017 21:15:33 +0100 Subject: [PATCH 2/2] fix php 5.4 --- tests/ImageManagerTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/ImageManagerTest.php b/tests/ImageManagerTest.php index 7f0a78c3..e23d9127 100644 --- a/tests/ImageManagerTest.php +++ b/tests/ImageManagerTest.php @@ -1,6 +1,5 @@ make('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'); - $this->assertInstanceOf(Image::class, $image); - $this->assertInstanceOf(Imagick::class, $image->getCore()); + $this->assertInstanceOf('Intervention\Image\Image', $image); + $this->assertInstanceOf('Imagick', $image->getCore()); } }