Need way to override Horde config when creating Prefs object
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 16 Nov 2010 04:52:41 +0000 (21:52 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 16 Nov 2010 07:01:23 +0000 (00:01 -0700)
framework/Core/lib/Horde/Core/Factory/Prefs.php
framework/Core/lib/Horde/Registry.php

index 8d72ead..5842159 100644 (file)
@@ -55,13 +55,23 @@ class Horde_Core_Factory_Prefs
      * Return the Horde_Prefs:: instance.
      *
      * @param string $scope  The scope for this set of preferences.
-     * @param array $opts    See Horde_Prefs::__construct().
+     * @param array $opts    See Horde_Prefs::__construct().  Additional
+     *                       parameters:
+     * <pre>
+     * driver - (boolean) Use this driver instead of the value in the Horde
+     *          config.
+     * driver_params - (array) Use these driver parameters instead of the
+     *                 values in the Horde config.
+     * </pre>
      *
      * @return Horde_Prefs  The singleton instance.
      */
     public function create($scope = 'horde', array $opts = array())
     {
-        if (empty($GLOBALS['conf']['prefs']['driver'])) {
+        if (array_key_exists('driver', $opts)) {
+            $driver = $opts['driver'];
+            $params = array();
+        } elseif (empty($GLOBALS['conf']['prefs']['driver'])) {
             $driver = null;
             $params = array();
         } else {
@@ -69,6 +79,10 @@ class Horde_Core_Factory_Prefs
             $params = Horde::getDriverConfig('prefs', $driver);
         }
 
+        if (array_key_exists('driver_params', $opts)) {
+            $params = $opts['driver_params'];
+        }
+
         $opts = array_merge(array(
             'cache' => true,
             'logger' => $this->_injector->getInstance('Horde_Log_Logger'),
@@ -118,7 +132,7 @@ class Horde_Core_Factory_Prefs
                       $hooks_driver
                   );
 
-            if ($opts['cache']) {
+            if ($driver && $opts['cache']) {
                 $opts['cache'] = new Horde_Core_Prefs_Cache_Session($opts['user']);
             } else {
                 unset($opts['cache']);
index fee181a..3a81305 100644 (file)
@@ -1335,8 +1335,7 @@ class Horde_Registry
             /* If there is no logged in user, return an empty Horde_Prefs
              * object with just default preferences. */
             $opts = array(
-                'cache' => null,
-                'session' => true
+                'driver' => null
             );
         }