More refactoring to use exceptions
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 1 Oct 2009 20:43:29 +0000 (16:43 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 1 Oct 2009 20:45:10 +0000 (16:45 -0400)
Fixes issue in Bug: 8623 as well.

12 files changed:
ansel/faces/image.php
ansel/img/mini.php
ansel/img/prettythumb.php
ansel/img/screen.php
ansel/img/thumb.php
ansel/lib/Ansel.php
ansel/lib/Api.php
ansel/lib/Faces/Base.php
ansel/lib/Image.php
ansel/lib/ImageView/plainstack.php
ansel/lib/ImageView/polaroidstack.php
ansel/lib/ImageView/roundedstack.php

index 41628de..693b9e9 100644 (file)
@@ -23,8 +23,13 @@ $result = $faces->getImageFacesData($image_id);
 // or if we were asked to explicitly try again.
 if (($reload || empty($result))) {
     $image = &$ansel_storage->getImage($image_id);
-    $image->createView('screen');
-    $result = $faces->getFromPicture($image_id, $autocreate);
+    try {
+        $image->createView('screen');
+        $result = $faces->getFromPicture($image_id, $autocreate);
+    } catch (Horde_Exception $e) {
+        Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
+        $result = null;
+    }
 }
 
 if (!empty($result)) {
index b90aedb..0c14a03 100644 (file)
@@ -26,9 +26,10 @@ if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) {
 /* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */
 if ($conf['vfs']['src'] == 'sendfile') {
     /* Need to ensure the file exists */
-    $result = $image->createView('mini', 'ansel_default');
-    if (is_a($result, 'PEAR_Error')) {
-        Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+    try {
+        $image->createView('mini', 'ansel_default');
+    } catch (Horde_Exception $e) {
+        Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
         exit;
     }
     $filename = $ansel_vfs->readFile($image->getVFSPath('mini'), $image->getVFSName('mini'));
index 22dbbd3..6c3cbd3 100644 (file)
@@ -27,9 +27,10 @@ if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) {
 /* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */
 if ($conf['vfs']['src'] == 'sendfile') {
     /* Need to ensure the file exists */
-    $result = $image->createView('prettythumb', $style);
-    if (is_a($result, 'PEAR_Error')) {
-        Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
+    try {
+        $image->createView('prettythumb', $style);
+    } catch (Horde_Exception $e) {
+        Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
         exit;
     }
     $filename = $ansel_vfs->readFile($image->getVFSPath('prettythumb', $style), $image->getVFSName('prettythumb'));
index 2ee835b..d7ec536 100644 (file)
@@ -26,8 +26,9 @@ if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) {
 /* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */
 if ($conf['vfs']['src'] == 'sendfile') {
     /* Need to ensure the file exists */
-    $result = $image->createView('screen', 'ansel_default');
-    if (is_a($result, 'PEAR_Error')) {
+    try {
+        $image->createView('screen', 'ansel_default');
+    } catch (Horde_Exception $e) {
         Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
         exit;
     }
index 33a6553..4c4700e 100644 (file)
@@ -26,8 +26,9 @@ if (!$gallery->hasPermission(Horde_Auth::getAuth(), PERMS_READ)) {
 /* Sendfile support. Lighttpd < 1.5 only understands the X-LIGHTTPD-send-file header */
 if ($conf['vfs']['src'] == 'sendfile') {
     /* Need to ensure the file exists */
-    $result = $image->createView('thumb', 'ansel_default');
-    if (is_a($result, 'PEAR_Error')) {
+    try {
+        $image->createView('thumb', 'ansel_default');
+    } catch (Horde_Exception $e) {
         Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
         exit;
     }
index 830a19f..725c5dc 100644 (file)
@@ -474,10 +474,15 @@ class Ansel
             ($viewHash = Ansel_Image::viewExists($imageId, $view, $style)) === false) {
             // We have to make sure the image exists first, since we won't
             // be going through img/*.php to auto-create it.
-            if (is_a($image = $ansel_storage->getImage($imageId), 'PEAR_Error')) {
+            try {
+                $image = $ansel_storage->getImage($imageId);
+            } catch (Horde_Exception $e) {
+                Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
                 return Ansel::getErrorImage($view);
             }
-            if (is_a($result = $image->createView($view, $style, false), 'PEAR_Error')) {
+            try {
+                $image->createView($view, $style, false);
+            } catch (Horde_Exception $e) {
                 return Ansel::getErrorImage($view);
             }
             $viewHash = $image->getViewHash($view, $style) . '/'
index 1c94739..32d2c7a 100644 (file)
@@ -680,9 +680,6 @@ class Ansel_Api extends Horde_Registry_Api
         } else {
             // Load View
             $result = $image->load($view, $style);
-            if (is_a($result, 'PEAR_Error')) {
-                return $result;
-            }
 
             // Return image content
             $data = $image->_image->raw();
index 639a239..6f27327 100644 (file)
@@ -340,7 +340,7 @@ class Ansel_Faces_Base
             $image = &$GLOBALS['ansel_storage']->getImage($image_id);
 
             // Actually create the image.
-            $result = $this->createView(
+            $this->createView(
                 $face_id,
                 $image,
                 $data['face_x1'],
@@ -449,7 +449,7 @@ class Ansel_Faces_Base
         $image->load('screen');
 
         // Process the image
-        $result = $this->createView($face_id,
+        $this->createView($face_id,
                                     $image,
                                     $x1,
                                     $y1,
index a2dcf54..9b51397 100644 (file)
@@ -175,7 +175,8 @@ class Ansel_Image
      * @param string $view   Which view to load.
      * @param string $style  The named gallery style.
      *
-     * @return mixed  True || PEAR_Error
+     * @return boolean
+     * @throws Horde_Exception
      */
     function load($view = 'full', $style = null)
     {
@@ -193,11 +194,7 @@ class Ansel_Image
         if (!empty($this->_loaded[$viewHash])) {
             return true;
         }
-
-        $result = $this->createView($view, $style);
-        if (is_a($result, 'PEAR_Error')) {
-            return $result;
-        }
+        $this->createView($view, $style);
 
         /* If createView() had to resize the full image, we've already
          * loaded the data, so return now. */
@@ -210,15 +207,12 @@ class Ansel_Image
 
         /* Get the VFS info. */
         $vfspath = $this->getVFSPath($view, $style);
-        if (is_a($vfspath, 'PEAR_Error')) {
-            return $vfspath;
-        }
 
         /* Read in the requested view. */
         $data = $GLOBALS['ansel_vfs']->read($vfspath, $this->getVFSName($view));
         if (is_a($data, 'PEAR_Error')) {
             Horde::logMessage($date, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return $data;
+            throw new Horde_Exception($data->getMessage());
         }
 
         $this->_data[$viewHash] = $data;
@@ -272,6 +266,9 @@ class Ansel_Image
      *
      * @param string $view  Which view to create.
      * @param string $style  A named gallery style
+     *
+     * @return boolean
+     * @throws Horde_Exception
      */
     function createView($view, $style = null)
     {
@@ -295,7 +292,7 @@ class Ansel_Image
                                             $this->getVFSName('full'));
         if (is_a($data, 'PEAR_Error')) {
             Horde::logMessage($data, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return $data;
+            throw new Horde_Exception($data->getMessage());
         }
         $this->_image->loadString($this->getVFSPath('full') . '/' . $this->id, $data);
         $styleDef = Ansel::getStyleDefinition($style);
@@ -328,7 +325,11 @@ class Ansel_Image
 
         $view = $this->getViewHash($view, $style);
 
-        $this->_data[$view] = $this->_image->raw();
+        try {
+            $this->_data[$view] = $this->_image->raw();
+        } catch (Horde_Image_Exception $e) {
+            throw new Horde_Exception($e);
+        }
         $this->_image->loadString($vfspath . '/' . $this->id,
                                   $this->_data[$view]);
         $this->_loaded[$view] = true;
@@ -777,13 +778,12 @@ class Ansel_Image
             echo $data;
             return;
         }
-
-        if (is_a($result = $this->load($view, $style), 'PEAR_Error')) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            return $result;
+        try {
+            $this->load($view, $style);
+            $this->_image->display();
+        } catch (Horde_Exception $e) {
+            Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
         }
-
-        $this->_image->display();
     }
 
     /**
@@ -793,10 +793,12 @@ class Ansel_Image
      */
     function toFile($view = 'full')
     {
-        if (is_a(($result = $this->load($view)), 'PEAR_Error')) {
-            return $result;
+        try {
+            $this->load($view);
+            return $this->_image->toFile($this->_dirty ? false : $this->_data[$view]);
+        } catch (Horde_Exception $e) {
+            Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
         }
-        return $this->_image->toFile($this->_dirty ? false : $this->_data[$view]);
     }
 
     /**
@@ -806,10 +808,12 @@ class Ansel_Image
      */
     function getDimensions($view = 'full')
     {
-        if (is_a(($result = $this->load($view)), 'PEAR_Error')) {
-            return $result;
+        try {
+            $this->load($view);
+            return $this->_image->getDimensions();
+        } catch (Horde_Exception $e) {
+            Horde::logMessage($e->getMessage(), __FILE__, __LINE__);
         }
-        return $this->_image->getDimensions();
     }
 
     /**
index ab26198..ce1a05b 100644 (file)
@@ -16,9 +16,6 @@ class Ansel_ImageView_plainstack extends Ansel_ImageView {
         $style = $this->_params['style'];
         foreach ($images as $image) {
             $result = $image->load('screen');
-            if (is_a($result, 'PEAR_Error')) {
-                return $result;
-            }
             $imgobjs[] = $image->_image;
         }
 
index 697f66e..c80330b 100644 (file)
@@ -15,10 +15,7 @@ class Ansel_ImageView_polaroidstack extends Ansel_ImageView {
         $images = $this->_getStackImages();
         $style = $this->_params['style'];
         foreach ($images as $image) {
-            $result = $image->load('screen');
-            if (is_a($result, 'PEAR_Error')) {
-                return $result;
-            }
+            $image->load('screen');
             $imgobjs[] = $image->_image;
         }
 
index a646c30..f874445 100644 (file)
@@ -17,9 +17,6 @@ class Ansel_ImageView_roundedstack extends Ansel_ImageView {
         $style = $this->_params['style'];
         foreach ($images as $image) {
             $result = $image->load('screen');
-            if (is_a($result, 'PEAR_Error')) {
-                return $result;
-            }
             $imgobjs[] = $image->_image;
         }