From c518436bfc4d546820363e60a6267dd22ee9a6e1 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 17 Jul 2009 13:37:59 -0600 Subject: [PATCH] throw exceptions instead of calling Horde::fatal() --- framework/Auth/lib/Horde/Auth/Cyrus.php | 4 ++- framework/Auth/lib/Horde/Auth/Signup/Sql.php | 7 +++-- framework/Core/lib/Horde.php | 25 +++++++--------- framework/Core/lib/Horde/Help.php | 3 +- framework/Core/lib/Horde/Registry.php | 34 +++++++++++----------- framework/Crypt/lib/Horde/Crypt/Pgp.php | 2 +- .../Horde/SessionHandler/horde-active-sessions.php | 6 ++-- 7 files changed, 41 insertions(+), 40 deletions(-) diff --git a/framework/Auth/lib/Horde/Auth/Cyrus.php b/framework/Auth/lib/Horde/Auth/Cyrus.php index fd7ec5cc7..acac535c9 100644 --- a/framework/Auth/lib/Horde/Auth/Cyrus.php +++ b/framework/Auth/lib/Horde/Auth/Cyrus.php @@ -115,6 +115,8 @@ class Horde_Auth_Cyrus extends Horde_Auth_Base * Constructor. * * @param array $params A hash containing connection parameters. + * + * @throws Horde_Exception */ public function __construct($params = array()) { @@ -136,7 +138,7 @@ class Horde_Auth_Cyrus extends Horde_Auth_Base if (!$this->_backend->hasCapability('add') || !$this->_backend->hasCapability('update') || !$this->_backend->hasCapability('remove')) { - Horde::fatal('Horde_Auth_Cyrus: Backend does not have required capabilites.', __FILE__, __LINE__); + throw new Horde_Exception('Horde_Auth_Cyrus: Backend does not have required capabilites.'); } $this->_capabilities['list'] = $this->_backend->hasCapability('list'); diff --git a/framework/Auth/lib/Horde/Auth/Signup/Sql.php b/framework/Auth/lib/Horde/Auth/Signup/Sql.php index fc745de96..13ada429e 100644 --- a/framework/Auth/lib/Horde/Auth/Signup/Sql.php +++ b/framework/Auth/lib/Horde/Auth/Signup/Sql.php @@ -205,7 +205,8 @@ class Horde_Auth_Signup_Sql extends Horde_Auth_Signup /** * Attempts to open a connection to the sql server. * - * @return boolean True on success; exits (Horde::fatal()) on error. + * @return boolean True on success. + * @throws Horde_Exception */ protected function _connect() { @@ -227,7 +228,7 @@ class Horde_Auth_Signup_Sql extends Horde_Auth_Signup unset($params['charset']); $this->_write_db = MDB2::factory($params); if (is_a($this->_write_db, 'PEAR_Error')) { - Horde::fatal($this->_write_db, __FILE__, __LINE__); + throw new Horde_Exception($this->_write_db); } /* Set DB portability options. */ @@ -246,7 +247,7 @@ class Horde_Auth_Signup_Sql extends Horde_Auth_Signup $params = array_merge($params, $this->_params['read']); $this->_db = MDB2::factory($params); if (is_a($this->_db, 'PEAR_Error')) { - Horde::fatal($this->_db, __FILE__, __LINE__); + thorw new Horde_Exception($this->_db); } /* Set DB portability options. */ diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index d1a26045b..4cf67cb6d 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -136,6 +136,7 @@ class Horde * instantiated. * * @return mixed Log object on success, false if disabled. + * @throws Horde_Exception */ static public function getLogger() { @@ -156,15 +157,15 @@ class Horde empty($conf['log']['name']) || empty($conf['log']['ident']) || !isset($conf['log']['params'])) { - self::fatal(new Horde_Exception('Horde is not correctly configured to log error messages. You must configure at least a text file log in horde/config/conf.php.'), __FILE__, __LINE__, false); + throw new Horde_Exception('Horde is not correctly configured to log error messages. You must configure at least a text file log in horde/config/conf.php.'); } self::$_logger = Log::singleton($conf['log']['type'], $conf['log']['name'], $conf['log']['ident'], $conf['log']['params']); - if (!is_a(self::$_logger, 'Log')) { - self::fatal(new Horde_Exception('An error has occurred. Furthermore, Horde encountered an error attempting to log this error. Please check your Horde logging configuration in horde/config/conf.php.'), __FILE__, __LINE__, false); + if (!self::$_logger instanceof Log) { + throw new Horde_Exception('An error has occurred. Furthermore, Horde encountered an error attempting to log this error. Please check your Horde logging configuration in horde/config/conf.php.'); } return self::$_logger; @@ -436,11 +437,7 @@ HTML; case 'login': /* Get an Auth object. */ - try { - $auth = Horde_Auth::singleton($GLOBALS['conf']['auth']['driver']); - } catch (Horde_Exception $e) { - Horde::fatal($e, __FILE__, __LINE__); - } + $auth = Horde_Auth::singleton($GLOBALS['conf']['auth']['driver']); return $auth->getLoginScreen('', $referrer ? self::selfUrl(true) : null); case 'options': @@ -824,6 +821,8 @@ HTML; * @param string $file The configuration file that should contain * these settings. * @param string $variable The name of the configuration variable. + * + * @throws Horde_Exception */ static public function assertDriverConfig($params, $driver, $fields, $name = null, @@ -840,22 +839,20 @@ HTML; $fileroot = isset($registry) ? $registry->get('fileroot') : ''; if (!is_array($params) || !count($params)) { - self::fatal(new Horde_Exception( + throw new Horde_Exception( sprintf(_("No configuration information specified for %s."), $name) . "\n\n" . sprintf(_("The file %s should contain some %s settings."), $fileroot . '/config/' . $file, - sprintf("%s['%s']['params']", $variable, $driver))), - __FILE__, __LINE__); + sprintf("%s['%s']['params']", $variable, $driver))); } foreach ($fields as $field) { if (!isset($params[$field])) { - self::fatal(new Horde_Exception( + throw new Horde_Exception( sprintf(_("Required \"%s\" not specified in %s configuration."), $field, $name) . "\n\n" . sprintf(_("The file %s should contain a %s setting."), $fileroot . '/config/' . $file, - sprintf("%s['%s']['params']['%s']", $variable, $driver, $field))), - __FILE__, __LINE__); + sprintf("%s['%s']['params']['%s']", $variable, $driver, $field))); } } } diff --git a/framework/Core/lib/Horde/Help.php b/framework/Core/lib/Horde/Help.php index cc1a1ea25..300b6c951 100644 --- a/framework/Core/lib/Horde/Help.php +++ b/framework/Core/lib/Horde/Help.php @@ -246,12 +246,13 @@ class Horde_Help * Initializes the XML parser. * * @return boolean Returns true on success, false on failure. + * @throws Horde_Exception */ protected function _init() { if (!isset($this->_parser)) { if (!Horde_Util::extensionExists('xml')) { - Horde::fatal(PEAR::raiseError('The XML functions are not available. Rebuild PHP with --with-xml.'), __FILE__, __LINE__, false); + throw new Horde_Exception('The XML functions are not available. Rebuild PHP with --with-xml.'); } /* Create a new parser and set its default properties. */ diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 8a2603916..7d4389fe2 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -186,7 +186,7 @@ class Horde_Registry /* Stop system if Horde is inactive. */ if ($this->applications['horde']['status'] == 'inactive') { - Horde::fatal(_("This system is currently deactivated."), __FILE__, __LINE__); + throw new Horde_Exception(_("This system is currently deactivated.")); } /* Create the global Perms object. */ @@ -224,10 +224,12 @@ class Horde_Registry /** * Clone should never be called on this object. If it is, die. + * + * @throws Horde_Exception */ public function __clone() { - Horde::fatal('Horde_Registry objects should never be cloned.', __FILE__, __LINE__); + throw new Horde_Exception('Horde_Registry objects should never be cloned.'); } /** @@ -784,7 +786,7 @@ class Horde_Registry if (!isset($this->applications[$app]) || $this->applications[$app]['status'] == 'inactive' || ($this->applications[$app]['status'] == 'admin' && !Horde_Auth::isAdmin())) { - Horde::fatal($app . ' is not activated', __FILE__, __LINE__); + throw new Horde_Exception($app . ' is not activated.'); } /* If permissions checking is requested, return an error if the @@ -1142,6 +1144,8 @@ class Horde_Registry * * The custom session handler object will be contained in the global * 'horde_sessionhandler' variable. + * + * @throws Horde_Exception */ public function setupSessionHandler() { @@ -1152,7 +1156,7 @@ class Horde_Registry ini_set('session.use_only_cookies', 1); if (!empty($conf['cookie']['domain']) && strpos($conf['server']['name'], '.') === false) { - Horde::fatal('Session cookies will not work without a FQDN and with a non-empty cookie domain. Either use a fully qualified domain name like "http://www.example.com" instead of "http://example" only, or set the cookie domain in the Horde configuration to an empty value, or enable non-cookie (url-based) sessions in the Horde configuration.', __FILE__, __LINE__); + throw new Horde_Exception('Session cookies will not work without a FQDN and with a non-empty cookie domain. Either use a fully qualified domain name like "http://www.example.com" instead of "http://example" only, or set the cookie domain in the Horde configuration to an empty value, or enable non-cookie (url-based) sessions in the Horde configuration.'); } } @@ -1174,19 +1178,15 @@ class Horde_Registry $calls['destroy'], $calls['gc']); } elseif ($type != 'none') { - try { - $sh = Horde_SessionHandler::singleton($conf['sessionhandler']['type'], array_merge(Horde::getDriverConfig('sessionhandler', $conf['sessionhandler']['type']), array('memcache' => !empty($conf['sessionhandler']['memcache'])))); - ini_set('session.save_handler', 'user'); - session_set_save_handler(array(&$sh, 'open'), - array(&$sh, 'close'), - array(&$sh, 'read'), - array(&$sh, 'write'), - array(&$sh, 'destroy'), - array(&$sh, 'gc')); - $GLOBALS['horde_sessionhandler'] = $sh; - } catch (Horde_Exception $e) { - Horde::fatal(new Horde_Exception('Horde is unable to correctly start the custom session handler.'), __FILE__, __LINE__, false); - } + $sh = Horde_SessionHandler::singleton($conf['sessionhandler']['type'], array_merge(Horde::getDriverConfig('sessionhandler', $conf['sessionhandler']['type']), array('memcache' => !empty($conf['sessionhandler']['memcache'])))); + ini_set('session.save_handler', 'user'); + session_set_save_handler(array(&$sh, 'open'), + array(&$sh, 'close'), + array(&$sh, 'read'), + array(&$sh, 'write'), + array(&$sh, 'destroy'), + array(&$sh, 'gc')); + $GLOBALS['horde_sessionhandler'] = $sh; } } diff --git a/framework/Crypt/lib/Horde/Crypt/Pgp.php b/framework/Crypt/lib/Horde/Crypt/Pgp.php index 7c394a742..afbbb2675 100644 --- a/framework/Crypt/lib/Horde/Crypt/Pgp.php +++ b/framework/Crypt/lib/Horde/Crypt/Pgp.php @@ -130,7 +130,7 @@ class Horde_Crypt_Pgp extends Horde_Crypt $this->_tempdir = Horde_Util::createTempDir(true, $params['temp']); if (empty($params['program'])) { - Horde::fatal(new Horde_Exception('The location of the GnuPG binary must be given to the Horde_Crypt_Pgp:: class.'), __FILE__, __LINE__); + throw new Horde_Exception('The location of the GnuPG binary must be given to the Horde_Crypt_Pgp:: class.'); } /* Store the location of GnuPG and set common options. */ diff --git a/framework/SessionHandler/scripts/Horde/SessionHandler/horde-active-sessions.php b/framework/SessionHandler/scripts/Horde/SessionHandler/horde-active-sessions.php index e97ba2688..c6832a4ff 100755 --- a/framework/SessionHandler/scripts/Horde/SessionHandler/horde-active-sessions.php +++ b/framework/SessionHandler/scripts/Horde/SessionHandler/horde-active-sessions.php @@ -38,18 +38,18 @@ require_once HORDE_BASE . '/lib/base.php'; /* Check for sessionhandler object. */ if (empty($GLOBALS['horde_sessionhandler'])) { - Horde::fatal(PEAR::raiseError('Horde is unable to load the session handler'), __FILE__, __LINE__, false); + throw new Horde_Exception('Horde is unable to load the session handler'); } $type = !empty($conf['sessionhandler']['type']) ? $conf['sessionhandler']['type'] : 'builtin'; if ($type == 'external') { - Horde::fatal(PEAR::raiseError('Session counting is not supported in the \'external\' SessionHandler at this time.'), __FILE__, __LINE__, false); + throw new Horde_Exception('Session counting is not supported in the \'external\' SessionHandler at this time.'); } $sessions = $GLOBALS['horde_sessionhandler']->getSessionsInfo(); if (is_a($sessions, 'PEAR_Error')) { - Horde::fatal($sessions, __FILE__, __LINE__, false); + throw new Horde_Exception($sessions); } if (($argc < 2) || (($argv[1] != '-l') && ($argv[1] != '-ll'))) { -- 2.11.0