summaryrefslogtreecommitdiffstats
path: root/application/libraries/Image.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2015-05-02 16:59:22 +0200
committerFlorian Pritz <bluewind@xinu.at>2015-05-02 16:59:22 +0200
commit70567d2c1eba3ae3182de82f2fdeea5fc44253a6 (patch)
tree7b9bfee8bc4d731055a3a19c1106660cddb8fa61 /application/libraries/Image.php
parent4f1b3a1cbf09d63a6e450680bf7a7a6946cdc28e (diff)
l\Image: Refactor best_driver/read
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/libraries/Image.php')
-rw-r--r--application/libraries/Image.php25
1 files changed, 13 insertions, 12 deletions
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);
}