Remove explicit reference to _SESSION in SessionHandler object
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 12 Oct 2010 20:12:54 +0000 (14:12 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 12 Oct 2010 20:31:25 +0000 (14:31 -0600)
framework/Core/lib/Horde/Core/Factory/SessionHandler.php
framework/SessionHandler/lib/Horde/SessionHandler.php

index 2511c4e..32362fd 100644 (file)
@@ -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;
+    }
+
 }
index 2a69d82..6df6f58 100644 (file)
@@ -50,19 +50,17 @@ abstract class Horde_SessionHandler
     protected $_logger;
 
     /**
-     * Session variable name.
-     *
-     * @var string
-     */
-    protected $_session = 'horde_sh';
-
-    /**
      * Constructor.
      *
      * @param array $params  Parameters:
      * <pre>
      * '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
+}