Fix testing and do not extend from Horde_Exception_Prior.
authorGunnar Wrobel <p@rdus.de>
Thu, 11 Feb 2010 17:21:51 +0000 (18:21 +0100)
committerGunnar Wrobel <wrobel@temple.(none)>
Wed, 17 Feb 2010 09:14:02 +0000 (10:14 +0100)
framework/Kolab_Server/lib/Horde/Kolab/Server/Exception.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Query/Ldap.php

index a62402a..79a7c88 100644 (file)
@@ -25,7 +25,7 @@
  * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
  * @link     http://pear.horde.org/index.php?package=Kolab_Server
  */
-class Horde_Kolab_Server_Exception extends Horde_Exception_Prior
+class Horde_Kolab_Server_Exception extends Horde_Exception
 {
     /**
      * Constants to define the error type.
index 516c15a..258d702 100644 (file)
@@ -185,15 +185,21 @@ implements Horde_Kolab_Server_Query_Interface
         Horde_Kolab_Server_Query_Element_Single $single,
         $operator
     ) {
-        $result = Horde_Ldap_Filter::create(
-            $this->_structure->mapExternalToInternalAttribute(
-                $single->getName()
-            ),
-            $operator,
-            $single->getValue()
-        );
-        $this->_handleError($result);
-        return $result;
+        try {
+            return Horde_Ldap_Filter::create(
+                $this->_structure->mapExternalToInternalAttribute(
+                    $single->getName()
+                ),
+                $operator,
+                $single->getValue()
+            );
+        } catch (Horde_Ldap_Exception $e) {
+            throw new Horde_Kolab_Server_Exception(
+                $e->getMessage(),
+                Horde_Kolab_Server_Exception::INVALID_QUERY,
+                $e
+            );
+        }
     }
 
     /**
@@ -208,9 +214,15 @@ implements Horde_Kolab_Server_Query_Interface
     public function convertNot(Horde_Kolab_Server_Query_Element_Not $not)
     {
         $elements = $not->getElements();
-        $result = Horde_Ldap_Filter::combine('!', $elements[0]->convert($this));
-        $this->_handleError($result);
-        return $result;
+        try {
+            return Horde_Ldap_Filter::combine('!', $elements[0]->convert($this));
+        } catch (Horde_Ldap_Exception $e) {
+            throw new Horde_Kolab_Server_Exception(
+                $e->getMessage(),
+                Horde_Kolab_Server_Exception::INVALID_QUERY,
+                $e
+            );
+        }
     }
 
     /**
@@ -259,30 +271,14 @@ implements Horde_Kolab_Server_Query_Interface
         foreach ($group->getElements() as $element) {
             $filters[] = $element->convert($this);
         }
-        $result = Horde_Ldap_Filter::combine($operator, $filters);
-        $this->_handleError($result);
-        return $result;
-    }
-
-    /**
-     * Check for a PEAR Error and convert it to an exception if necessary.
-     *
-     * @param mixed $result The result to be tested.
-     * @param code  $code   The error code to use in case the result is an error.
-     *
-     * @return NULL.
-     *
-     * @throws Horde_Kolab_Server_Exception If the connection failed.
-     *
-     * @throws Horde_Kolab_Server_Exception If the query is malformed.
-     */
-    private function _handleError(
-        $result,
-        $code = Horde_Kolab_Server_Exception::INVALID_QUERY
-    ) {
-        if ($result instanceOf PEAR_Error) {
-            throw new Horde_Kolab_Server_Exception($result, $code);
+        try {
+            return Horde_Ldap_Filter::combine($operator, $filters);
+        } catch (Horde_Ldap_Exception $e) {
+            throw new Horde_Kolab_Server_Exception(
+                $e->getMessage(),
+                Horde_Kolab_Server_Exception::INVALID_QUERY,
+                $e
+            );
         }
     }
-
 }
\ No newline at end of file