throw exceptions instead of calling Horde::fatal()
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 17 Jul 2009 19:37:59 +0000 (13:37 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 17 Jul 2009 19:37:59 +0000 (13:37 -0600)
framework/Auth/lib/Horde/Auth/Cyrus.php
framework/Auth/lib/Horde/Auth/Signup/Sql.php
framework/Core/lib/Horde.php
framework/Core/lib/Horde/Help.php
framework/Core/lib/Horde/Registry.php
framework/Crypt/lib/Horde/Crypt/Pgp.php
framework/SessionHandler/scripts/Horde/SessionHandler/horde-active-sessions.php

index fd7ec5c..acac535 100644 (file)
@@ -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');
index fc745de..13ada42 100644 (file)
@@ -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. */
index d1a2604..4cf67cb 100644 (file)
@@ -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)));
             }
         }
     }
index cc1a1ea..300b6c9 100644 (file)
@@ -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. */
index 8a26039..7d4389f 100644 (file)
@@ -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;
         }
     }
 
index 7c394a7..afbbb26 100644 (file)
@@ -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. */
index e97ba26..c6832a4 100755 (executable)
@@ -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'))) {