From 70567d2c1eba3ae3182de82f2fdeea5fc44253a6 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 2 May 2015 16:59:22 +0200 Subject: l\Image: Refactor best_driver/read Signed-off-by: Florian Pritz --- application/libraries/Image.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'application') diff --git a/application/libraries/Image.php b/application/libraries/Image.php index f18ddea53..deefc760d 100644 --- a/application/libraries/Image.php +++ b/application/libraries/Image.php @@ -80,10 +80,13 @@ namespace libraries; class Image { private $driver; - private $image_drivers = array( - "libraries\Image\Drivers\GD", - "libraries\Image\Drivers\imagemagick", - ); + private static function get_image_drivers() + { + return array( + "libraries\Image\Drivers\GD", + "libraries\Image\Drivers\imagemagick", + ); + } /** * Create a new object and load the contents of file. @@ -101,7 +104,7 @@ class Image { * @param mimetype mimetype the driver should support * @return driver from $drivers or NULL if no driver supports the type */ - private function best_driver($drivers, $mimetype) + private static function best_driver($drivers, $mimetype) { $best = 0; $best_driver = null; @@ -113,6 +116,10 @@ class Image { } } + if ($best_driver === NULL) { + throw new \exceptions\PublicApiException("libraries/Image/unsupported-image-type", "Unsupported image type"); + } + return $best_driver; } @@ -123,13 +130,7 @@ class Image { public function read($file) { $mimetype = mimetype($file); - - $driver = $this->best_driver($this->image_drivers, $mimetype); - - if ($driver === NULL) { - throw new \exceptions\ApiException("libraries/Image/unsupported-image-type", "Unsupported image type"); - } - + $driver = self::best_driver(self::get_image_drivers(), $mimetype); $this->driver = new $driver($file); } -- cgit v1.2.3-24-g4f1b