From: Michael M Slusarz Date: Mon, 13 Jul 2009 17:03:50 +0000 (-0600) Subject: Horde::callHook() now throws a Horde_Exception X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f11b2c41c8760307dc2a6d5546aba1484b4840d0;p=horde.git Horde::callHook() now throws a Horde_Exception --- diff --git a/framework/Auth/lib/Horde/Auth.php b/framework/Auth/lib/Horde/Auth.php index b1dfea29c..976ab2957 100644 --- a/framework/Auth/lib/Horde/Auth.php +++ b/framework/Auth/lib/Horde/Auth.php @@ -511,12 +511,15 @@ class Horde_Auth { $userId = self::addHook(trim($userId)); - if (!empty($GLOBALS['conf']['hooks']['postauthenticate']) && - !Horde::callHook('_horde_hook_postauthenticate', array($userId, $credentials, $realm), 'horde', false)) { - if (self::getAuthError() != self::REASON_MESSAGE) { - self::setAuthError(self::REASON_FAILED); - } - return false; + if (!empty($GLOBALS['conf']['hooks']['postauthenticate'])) { + try { + if (!Horde::callHook('_horde_hook_postauthenticate', array($userId, $credentials, $realm), 'horde')) { + if (self::getAuthError() != self::REASON_MESSAGE) { + self::setAuthError(self::REASON_FAILED); + } + return false; + } + } catch (Horde_Exception $e) {} } /* If we're already set with this userId, don't continue. */ @@ -685,17 +688,13 @@ class Horde_Auth * @param string $userId The authentication backend's user name. * * @return string The internal Horde user name. + * @throws Horde_Exception */ static public function addHook($userId) { - if (!empty($GLOBALS['conf']['hooks']['username'])) { - $newId = Horde::callHook('_username_hook_frombackend', array($userId)); - if (!is_a($newId, 'PEAR_Error')) { - return $newId; - } - } - - return $userId; + return empty($GLOBALS['conf']['hooks']['username']) + ? $userId + : Horde::callHook('_username_hook_frombackend', array($userId)); } /** @@ -710,17 +709,13 @@ class Horde_Auth * @param string $userId The internal Horde user name. * * @return string The authentication backend's user name. + * @throws Horde_Exception */ static public function removeHook($userId) { - if (!empty($GLOBALS['conf']['hooks']['username'])) { - $newId = Horde::callHook('_username_hook_tobackend', array($userId)); - if (!is_a($newId, 'PEAR_Error')) { - return $newId; - } - } - - return $userId; + return empty($GLOBALS['conf']['hooks']['username']) + ? $userId + : Horde::callHook('_username_hook_tobackend', array($userId)); } /** diff --git a/framework/Auth/lib/Horde/Auth/Driver.php b/framework/Auth/lib/Horde/Auth/Driver.php index 0fa3edc9d..13f67f333 100644 --- a/framework/Auth/lib/Horde/Auth/Driver.php +++ b/framework/Auth/lib/Horde/Auth/Driver.php @@ -74,12 +74,14 @@ class Horde_Auth_Driver $userId = trim($userId); if (!empty($GLOBALS['conf']['hooks']['preauthenticate'])) { - if (!Horde::callHook('_horde_hook_preauthenticate', array($userId, $credentials, $realm), 'horde', false)) { - if (Horde_Auth::getAuthError() != Horde_Auth::REASON_MESSAGE) { - Horde_Auth::setAuthError(Horde_Auth::REASON_FAILED); + try { + if (!Horde::callHook('_horde_hook_preauthenticate', array($userId, $credentials, $realm), 'horde')) { + if (Horde_Auth::getAuthError() != Horde_Auth::REASON_MESSAGE) { + Horde_Auth::setAuthError(Horde_Auth::REASON_FAILED); + } + return false; } - return false; - } + } catch (Horde_Exception $e) {} } /* Store the credentials being checked so that subclasses can modify diff --git a/framework/Auth/lib/Horde/Auth/Ldap.php b/framework/Auth/lib/Horde/Auth/Ldap.php index e2dd72311..22b0e021c 100644 --- a/framework/Auth/lib/Horde/Auth/Ldap.php +++ b/framework/Auth/lib/Horde/Auth/Ldap.php @@ -325,9 +325,6 @@ class Horde_Auth_Ldap extends Horde_Auth_Driver global $conf; if (!empty($conf['hooks']['authldap'])) { $entry = Horde::callHook('_horde_hook_authldap', array($userId, $credentials)); - if ($entry instanceof PEAR_Error) { - throw new Horde_Exception($entry); - } $dn = $entry['dn']; /* Remove the dn entry from the array. */ unset($entry['dn']); @@ -380,9 +377,6 @@ class Horde_Auth_Ldap extends Horde_Auth_Driver if (!empty($GLOBALS['conf']['hooks']['authldap'])) { $entry = Horde::callHook('_horde_hook_authldap', array($userId)); - if ($entry instanceof PEAR_Error) { - throw new Horde_Exception($entry); - } $dn = $entry['dn']; } else { /* Search for the user's full DN. */ @@ -419,9 +413,6 @@ class Horde_Auth_Ldap extends Horde_Auth_Driver if (!empty($GLOBLS['conf']['hooks']['authldap'])) { $entry = Horde::callHook('_horde_hook_authldap', array($oldID, $credentials)); - if ($entry instanceof PEAR_Error) { - throw new Horde_Exception($entry); - } $olddn = $entry['dn']; $entry = Horde::callHook('_horde_hook_authldap', array($newID, $credentials)); $newdn = $entry['dn']; diff --git a/framework/Auth/lib/Horde/Auth/Msad.php b/framework/Auth/lib/Horde/Auth/Msad.php index 5dc168dd3..93d94f944 100644 --- a/framework/Auth/lib/Horde/Auth/Msad.php +++ b/framework/Auth/lib/Horde/Auth/Msad.php @@ -76,7 +76,10 @@ class Horde_Auth_Msad extends Horde_Auth_Ldap /* Connect to the MSAD server. */ $this->_connect(); - $entry = Horde::callHook('_horde_hook_authmsad', array($accountName, $credentials), 'horde', null); + try { + $entry = Horde::callHook('_horde_hook_authmsad', array($accountName, $credentials), 'horde'); + } catch (Horde_Exception $e) {} + if (!is_null($entry)) { $dn = $entry['dn']; unset($entry['dn']); @@ -132,13 +135,14 @@ class Horde_Auth_Msad extends Horde_Auth_Ldap /* Connect to the MSAD server. */ $this->_connect(); - $entry = Horde::callHook('_horde_hook_authmsad', array($accountName), 'horde', null); - if (!is_null($entry)) { - $dn = $entry['dn']; - } else { + try { + $entry = Horde::callHook('_horde_hook_authmsad', array($accountName), 'horde'); + } catch (Horde_Exception $e) {} + + $dn = is_null($entry) /* Search for the user's full DN. */ - $dn = $this->_findDN($accountName); - } + ? $this->_findDN($accountName) + : $entry['dn']; if (!@ldap_delete($this->_ds, $dn)) { throw new Horde_Exception(sprintf(_("Horde_Auth_Msad: Unable to remove user \"%s\""), $accountName)); @@ -163,7 +167,10 @@ class Horde_Auth_Msad extends Horde_Auth_Ldap /* Connect to the MSAD server. */ $this->_connect(); - $entry = Horde::callHook('_horde_hook_authmsad', array($oldId, $credentials), 'horde', null); + try { + $entry = Horde::callHook('_horde_hook_authmsad', array($oldId, $credentials), 'horde'); + } catch (Horde_Exception $e) {} + if (!is_null($entry)) { $olddn = $entry['dn']; unset($entry['dn']); diff --git a/framework/Auth/lib/Horde/Auth/Signup.php b/framework/Auth/lib/Horde/Auth/Signup.php index 7656cd4bd..bcf3b0536 100644 --- a/framework/Auth/lib/Horde/Auth/Signup.php +++ b/framework/Auth/lib/Horde/Auth/Signup.php @@ -70,9 +70,6 @@ class Horde_Auth_Signup // Perform any preprocessing if requested. if ($conf['signup']['preprocess']) { $info = Horde::callHook('_horde_hook_signup_preprocess', array($info)); - if (is_a($info, 'PEAR_Error')) { - return $info; - } } // Check to see if the username already exists. @@ -88,14 +85,14 @@ class Horde_Auth_Signup } $result = true; + // Attempt to add/update any extra data handed in. if (!empty($info['extra'])) { - $result = false; - $result = Horde::callHook('_horde_hook_signup_addextra', - array($info['user_name'], $info['extra'])); - if (is_a($result, 'PEAR_Error')) { - Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_EMERG); - return $result; + try { + return Horde::callHook('_horde_hook_signup_addextra', array($info['user_name'], $info['extra'])); + } catch (Horde_Exception $e) { + Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_EMERG); + return PEAR::raiseError($e->getMessage(), $e->getCode()); } } @@ -118,11 +115,9 @@ class Horde_Auth_Signup // Perform any preprocessing if requested. if ($conf['signup']['preprocess']) { - $info = Horde::callHook('_horde_hook_signup_preprocess', - array($info)); - if (is_a($info, 'PEAR_Error')) { - return $info; - } + try { + $info = Horde::callHook('_horde_hook_signup_preprocess', array($info)); + } catch (Horde_Exception $e) {} } // Check to see if the username already exists. @@ -148,8 +143,9 @@ class Horde_Auth_Signup } if ($conf['signup']['queue']) { - $result = Horde::callHook('_horde_hook_signup_queued', - array($info['user_name'], $info)); + try { + $result = Horde::callHook('_horde_hook_signup_queued', array($info['user_name'], $info)); + } catch (Horde_Exception $e) {} } if (!empty($conf['signup']['email'])) { @@ -258,8 +254,11 @@ class HordeSignupForm extends Horde_Form { $this->addHidden('', 'url', 'text', false); /* Use hooks get any extra fields required in signing up. */ - $extra = Horde::callHook('_horde_hook_signup_getextra'); - if (!is_a($extra, 'PEAR_Error') && !empty($extra)) { + try { + $extra = Horde::callHook('_horde_hook_signup_getextra'); + } catch (Horde_Exception $e) {} + + if (!empty($extra)) { if (!isset($extra['user_name'])) { $this->addVariable(_("Choose a username"), 'user_name', 'text', true); } diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index 1d1dca080..7b25e780d 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -1791,16 +1791,10 @@ HTML; * function. * @param string $app If specified look for hooks in the config directory * of this app. - * @param mixed $error What to return if $app/config/hooks.php or $hook - * does not exist. If this is the string 'PEAR_Error' - * a PEAR error object is returned instead, detailing - * the failure. * - * @return mixed Either the results of the hook or PEAR error on failure. - * @todo Throw Horde_Exception + * @return mixed The results of the hook. */ - static public function callHook($hook, $args = array(), $app = 'horde', - $error = 'PEAR_Error') + static public function callHook($hook, $args = array(), $app = 'horde') { if (!isset(self::$_hooksLoaded[$app])) { try { @@ -1812,20 +1806,16 @@ HTML; } } - if (function_exists($hook)) { - $result = call_user_func_array($hook, $args); - if ($result instanceof PEAR_Error) { - self::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); - } - return $result; - } + if (!function_exists($hook)) { + throw new Horde_Exception(sprintf('Hook %s in application %s not called.', $hook, $app)); - if (is_string($error) && strcmp($error, 'PEAR_Error') == 0) { - $error = PEAR::raiseError(sprintf('Hook %s in application %s not called.', $hook, $app)); - self::logMessage($error, __FILE__, __LINE__, PEAR_LOG_DEBUG); } - return $error; + try { + return call_user_func_array($hook, $args); + } catch (Horde_Exception $e) { + self::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); + } } /** diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 35c1a92cf..eccf2d7a3 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -819,7 +819,9 @@ class Horde_Registry $this->_appStack[] = $app; /* Call post-push hook. */ - Horde::callHook('_horde_hook_post_pushapp', array($app), 'horde', null); + try { + Horde::callHook('_horde_hook_post_pushapp', array($app), 'horde'); + } catch (Horde_Exception $e) {} return true; }