From e27868edb482abc65fe2d993584c6eef924c0680 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 12 Oct 2010 14:12:54 -0600 Subject: [PATCH] Remove explicit reference to _SESSION in SessionHandler object --- .../Core/lib/Horde/Core/Factory/SessionHandler.php | 18 ++++++++++++++++ .../SessionHandler/lib/Horde/SessionHandler.php | 24 ++++++++++------------ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/framework/Core/lib/Horde/Core/Factory/SessionHandler.php b/framework/Core/lib/Horde/Core/Factory/SessionHandler.php index 2511c4ea2..32362fda3 100644 --- a/framework/Core/lib/Horde/Core/Factory/SessionHandler.php +++ b/framework/Core/lib/Horde/Core/Factory/SessionHandler.php @@ -69,6 +69,10 @@ class Horde_Core_Factory_SessionHandler } $params['logger'] = $logger; + $params['modified'] = array( + 'get' => array($this, 'getModified'), + 'set' => array($this, 'setModified') + ); $params['parse'] = array($this, 'readSessionData'); $driver = basename(strtolower($driver)); @@ -81,4 +85,18 @@ class Horde_Core_Factory_SessionHandler throw new Horde_SessionHandler_Exception('Driver not found: ' . $driver); } + /** + */ + public function getModified() + { + return $GLOBALS['session']['horde:session_mod']; + } + + /** + */ + public function setModified($date) + { + $GLOBALS['session']['horde:session_mod'] = $date; + } + } diff --git a/framework/SessionHandler/lib/Horde/SessionHandler.php b/framework/SessionHandler/lib/Horde/SessionHandler.php index 2a69d8232..6df6f5882 100644 --- a/framework/SessionHandler/lib/Horde/SessionHandler.php +++ b/framework/SessionHandler/lib/Horde/SessionHandler.php @@ -50,19 +50,17 @@ abstract class Horde_SessionHandler protected $_logger; /** - * Session variable name. - * - * @var string - */ - protected $_session = 'horde_sh'; - - /** * Constructor. * * @param array $params Parameters: *
      * 'logger' - (Horde_Log_Logger) A logger instance.
      *            DEFAULT: No logging
+     * 'modified' - (array) Callbacks used to store the session last modified
+     *              value.  Needs to define two keys: 'get' and 'set'. 'get'
+     *              returns the last modified value, 'set' receives the last
+     *              modified value as the only parameter.
+     *              DEFAULT: Not saved
      * 'noset' - (boolean) If true, don't set the save handler.
      *           DEFAULT: false
      * 'parse' - (callback) A callback function that parses session
@@ -83,7 +81,9 @@ abstract class Horde_SessionHandler
 
         $this->_params = $params;
 
-        register_shutdown_function(array($this, 'shutdown'));
+        if (isset($this->_params['modified'])) {
+            register_shutdown_function(array($this, 'shutdown'));
+        }
 
         if (empty($this->_params['noset'])) {
             ini_set('session.save_handler', 'user');
@@ -124,10 +124,8 @@ abstract class Horde_SessionHandler
     public function shutdown()
     {
         $curr_time = time();
-
-        if (!isset($_SESSION[$this->_session]) ||
-            ($curr_time >= $_SESSION[$this->_session])) {
-            $_SESSION[$this->_session] = $curr_time + (ini_get('session.gc_maxlifetime') / 2);
+        if ($curr_time >= intval(call_user_func($this->_params['modified']['get']))) {
+            call_user_func($this->_params['modified']['set'], $curr_time + (ini_get('session.gc_maxlifetime') / 2));
             $this->_force = true;
         }
     }
@@ -329,4 +327,4 @@ abstract class Horde_SessionHandler
         return $info;
     }
 
-}
\ No newline at end of file
+}
-- 
2.11.0