From e5c1c1e4b04596ca2c003272bad48996757b1d8d Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Thu, 11 Feb 2010 18:21:51 +0100 Subject: [PATCH] Fix testing and do not extend from Horde_Exception_Prior. --- .../lib/Horde/Kolab/Server/Exception.php | 2 +- .../lib/Horde/Kolab/Server/Query/Ldap.php | 68 ++++++++++------------ 2 files changed, 33 insertions(+), 37 deletions(-) diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Exception.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Exception.php index a62402ae0..79a7c88f6 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Exception.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Exception.php @@ -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. diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Query/Ldap.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Query/Ldap.php index 516c15abb..258d702fd 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Query/Ldap.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Query/Ldap.php @@ -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 -- 2.11.0