Add Horde_Core_Prefs_Session and use it as the Horde prefs driver
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 14 Oct 2010 18:10:57 +0000 (12:10 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 15 Oct 2010 16:37:59 +0000 (10:37 -0600)
framework/Core/lib/Horde/Core/Factory/Prefs.php
framework/Core/lib/Horde/Core/Prefs/Session.php [new file with mode: 0644]
framework/Core/package.xml

index 153c71e..6f181f3 100644 (file)
@@ -75,7 +75,7 @@ class Horde_Core_Factory_Prefs
     {
         if (empty($GLOBALS['conf']['prefs']['driver']) ||
             !empty($opts['session'])) {
-            $driver = 'Session';
+            $driver = 'Horde_Core_Prefs_Session';
             $params = array();
             unset($opts['session']);
         } else {
@@ -125,7 +125,7 @@ class Horde_Core_Factory_Prefs
                         $GLOBALS['notification']->push($this->_coreDict("The preferences backend is currently unavailable and your preferences have not been loaded. You may continue to use the system with default preferences."));
                     }
                 }
-                $this->_instances[$sig] = Horde_Prefs::factory('Session', $scope);
+                $this->_instances[$sig] = Horde_Prefs::factory('Horde_Core_Prefs_Session', $scope);
             }
         }
 
diff --git a/framework/Core/lib/Horde/Core/Prefs/Session.php b/framework/Core/lib/Horde/Core/Prefs/Session.php
new file mode 100644 (file)
index 0000000..d5a2898
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+/**
+ * Preferences storage implementation using Horde_Session.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author   Michael Slusarz <slusarz@horde.org>
+ * @category Horde
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @package  Core
+ */
+class Horde_Core_Prefs_Session extends Horde_Prefs
+{
+    /**
+     * Retrieves the requested set of preferences from the current session.
+     *
+     * @param string $scope  Scope specifier.
+     */
+    protected function _retrieve($scope)
+    {
+        global $session;
+
+        if (isset($session['horde:prefs_session/' . $scope])) {
+            $this->_scopes[$scope] = $session['horde:prefs_session/' . $scope];
+        }
+    }
+
+    /**
+     * Stores preferences in the current session.
+     */
+    public function store()
+    {
+        // Copy the current preferences into the session variable.
+        foreach ($this->_scopes as $scope => $prefs) {
+            foreach (array_keys($prefs) as $pref_name) {
+                // Clean the pref since it was just saved.
+                $prefs[$pref_name]['m'] &= ~Horde_Prefs::DIRTY;
+            }
+
+            $session['horde:prefs_session/' . $scope] = $prefs;
+        }
+    }
+
+    /**
+     * Perform cleanup operations.
+     *
+     * @param boolean $all  Cleanup all Horde preferences.
+     */
+    public function cleanup($all = false)
+    {
+        global $session;
+
+        // Perform a Horde-wide cleanup?
+        if ($all) {
+            unset($session['horde:prefs_session/']);
+        } else {
+            unset($session['horde:prefs_session/' . $this->_scope]);
+        }
+
+        parent::cleanup($all);
+    }
+
+}
index e25bafb..01e3e0b 100644 (file)
@@ -188,6 +188,7 @@ Application Framework.</description>
         <file name="Widgets.php" role="php" />
        </dir> <!-- /lib/Horde/Core/Prefs/Ui -->
        <file name="Identity.php" role="php" />
+       <file name="Session.php" role="php" />
        <file name="Ui.php" role="php" />
       </dir> <!-- /lib/Horde/Core/Prefs -->
       <dir name="Text">
@@ -479,6 +480,7 @@ Application Framework.</description>
    <install as="Horde/Core/Notification/Status.php" name="lib/Horde/Core/Notification/Status.php" />
    <install as="Horde/Core/Perms/Ui.php" name="lib/Horde/Core/Perms/Ui.php" />
    <install as="Horde/Core/Prefs/Identity.php" name="lib/Horde/Core/Prefs/Identity.php" />
+   <install as="Horde/Core/Prefs/Session.php" name="lib/Horde/Core/Prefs/Session.php" />
    <install as="Horde/Core/Prefs/Ui.php" name="lib/Horde/Core/Prefs/Ui.php" />
    <install as="Horde/Core/Prefs/Ui/Widgets.php" name="lib/Horde/Core/Prefs/Ui/Widgets.php" />
    <install as="Horde/Core/Text/Filter/Bbcode.php" name="lib/Horde/Core/Text/Filter/Bbcode.php" />