From 577a8c026e6a0980ac3b8ae713e63302eeec4a5d Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 14 Oct 2010 12:10:57 -0600 Subject: [PATCH] Add Horde_Core_Prefs_Session and use it as the Horde prefs driver --- framework/Core/lib/Horde/Core/Factory/Prefs.php | 4 +- framework/Core/lib/Horde/Core/Prefs/Session.php | 66 +++++++++++++++++++++++++ framework/Core/package.xml | 2 + 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 framework/Core/lib/Horde/Core/Prefs/Session.php diff --git a/framework/Core/lib/Horde/Core/Factory/Prefs.php b/framework/Core/lib/Horde/Core/Factory/Prefs.php index 153c71ec3..6f181f386 100644 --- a/framework/Core/lib/Horde/Core/Factory/Prefs.php +++ b/framework/Core/lib/Horde/Core/Factory/Prefs.php @@ -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 index 000000000..d5a28983c --- /dev/null +++ b/framework/Core/lib/Horde/Core/Prefs/Session.php @@ -0,0 +1,66 @@ + + * @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); + } + +} diff --git a/framework/Core/package.xml b/framework/Core/package.xml index e25bafb63..01e3e0b4a 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -188,6 +188,7 @@ Application Framework. + @@ -479,6 +480,7 @@ Application Framework. + -- 2.11.0