Update Horde_Util::assertDriverConfig() to H4 standards
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 8 Mar 2010 03:00:29 +0000 (20:00 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 9 Mar 2010 01:46:31 +0000 (18:46 -0700)
framework/Cache/lib/Horde/Cache/Sql.php
framework/Lock/lib/Horde/Lock/Sql.php
framework/Token/lib/Horde/Token/Sql.php
framework/Util/lib/Horde/Util.php

index 09efe86..c14fc8e 100644 (file)
@@ -350,10 +350,7 @@ class Horde_Cache_Sql extends Horde_Cache_Base
             return true;
         }
 
-        $result = Horde_Util::assertDriverConfig($this->_params, array('phptype'), 'cache SQL', array('driver' => 'cache'));
-        if (is_a($result, 'PEAR_Error')) {
-            throw new Horde_Exception($result->getMessage());
-        }
+        Horde_Util::assertDriverConfig($this->_params, array('phptype'), 'cache SQL');
 
         $this->_write_db = DB::connect(
             $this->_params,
index efc7dd8..a838278 100644 (file)
@@ -321,14 +321,13 @@ class Horde_Lock_Sql extends Horde_Lock
             return true;
         }
 
-        $result = Horde_Util::assertDriverConfig($this->_params, array('phptype'),
-                                           'Lock SQL', array('driver' => 'lock'));
-        if (is_a($result, 'PEAR_Error')) {
-            Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR);
-            throw new Horde_Lock_Exception($result->getMessage());
+        try {
+            Horde_Util::assertDriverConfig($this->_params, array('phptype'), 'Lock SQL');
+        } catch (Horde_Exception $e) {
+            Horde::logMessage($e, __FILE__, __LINE__, PEAR_LOG_ERR);
+            throw new Horde_Lock_Exception($e);
         }
 
-        require_once 'DB.php';
         $this->_write_db = &DB::connect(
             $this->_params,
             array('persistent' => !empty($this->_params['persistent']),
index cb30b38..c77de0e 100644 (file)
@@ -172,7 +172,7 @@ class Horde_Token_Sql extends Horde_Token
             return;
         }
 
-        Horde_Util::assertDriverConfig($this->_params, array('phptype'), 'token SQL', array('driver' => 'token'));
+        Horde_Util::assertDriverConfig($this->_params, array('phptype'), 'token SQL');
 
         if (!isset($this->_params['database'])) {
             $this->_params['database'] = '';
index e5e9c2b..cccea44 100644 (file)
 class Horde_Util
 {
     /* Error code for a missing driver configuration. */
-    const HORDE_ERROR_DRIVER_CONFIG_MISSING = 1;
+    const DRIVER_CONFIG_MISSING = 1;
 
     /* Error code for an incomplete driver configuration. */
-    const HORDE_ERROR_DRIVER_CONFIG = 2;
+    const DRIVER_CONFIG = 2;
 
     /**
      * A list of random patterns to use for overwriting purposes.
@@ -727,19 +727,17 @@ class Horde_Util
 
     /**
      * Checks if all necessary parameters for a driver's configuration are set
-     * and returns a PEAR_Error if something is missing.
+     * and throws an exception if something is missing.
      *
      * @param array $params   The configuration array with all parameters.
      * @param array $fields   An array with mandatory parameter names for this
      *                        driver.
      * @param string $name    The clear text name of the driver. If not
      *                        specified, the application name will be used.
-     * @param array $info     A hash containing detailed information about the
-     *                        driver. Will be passed as the userInfo to the
-     *                        PEAR_Error.
+     *
+     * @throws Horde_Exception
      */
-    static public function assertDriverConfig($params, $fields, $name,
-                                              $info = array())
+    static public function assertDriverConfig($params, $fields, $name)
     {
         $info = array_merge($info, array(
             'params' => $params,
@@ -748,12 +746,12 @@ class Horde_Util
         ));
 
         if (!is_array($params) || !count($params)) {
-            return PEAR::throwError(sprintf(_("No configuration information specified for %s."), $name), self::HORDE_ERROR_DRIVER_CONFIG_MISSING, $info);
+            throw new Horde_Exception(sprintf('No configuration information specified for %s.', $name), self::DRIVER_CONFIG_MISSING);
         }
 
         foreach ($fields as $field) {
             if (!isset($params[$field])) {
-                return PEAR::throwError(sprintf(_("Required \"%s\" not specified in configuration."), $field, $name), self::HORDE_ERROR_DRIVER_CONFIG, $info);
+                throw new Horde_Exception(sprintf('Required "%s" not specified in configuration.', $field, $name), self::DRIVER_CONFIG);
             }
         }
     }