Move readSessionData() to horde/Core from horde/Auth
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 1 Jun 2010 05:50:53 +0000 (23:50 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 2 Jun 2010 03:32:16 +0000 (21:32 -0600)
framework/Auth/lib/Horde/Auth.php
framework/Core/lib/Horde/Core/Binder/SessionHandler.php
framework/SessionHandler/lib/Horde/SessionHandler/Driver.php
framework/SessionHandler/package.xml

index 5e522d7..19a0416 100644 (file)
@@ -897,49 +897,6 @@ class Horde_Auth
     }
 
     /**
-     * Reads session data to determine if it contains Horde authentication
-     * credentials.
-     *
-     * @param string $session_data  The session data.
-     * @param boolean $info         Return session information.  The following
-     *                              information is returned: userid,
-     *                              timestamp, remoteAddr, browser.
-     *
-     * @return array  An array of the user's sesion information if
-     *                authenticated or false.  The following information is
-     *                returned: userid, timestamp, remoteAddr, browser, apps.
-     */
-    static public function readSessionData($session_data)
-    {
-        if (empty($session_data) ||
-            (($pos = strpos($session_data, 'horde_auth|')) === false)) {
-            return false;
-        }
-
-        $pos += 11;
-        $endpos = $pos + 1;
-
-        while ($endpos !== false) {
-            $endpos = strpos($session_data, '|', $endpos);
-            $data = @unserialize(substr($session_data, $pos, $endpos));
-            if (is_array($data)) {
-                return empty($data)
-                    ? false
-                    : array(
-                        'apps' => empty($data['app']) ? array('horde') : array_keys($data['app']),
-                        'browser' => $data['browser'],
-                        'remoteAddr' => $data['remoteAddr'],
-                        'timestamp' => $data['timestamp'],
-                        'userid' => $data['userId']
-                    );
-            }
-            ++$endpos;
-        }
-
-        return false;
-    }
-
-    /**
      * Sets the error message for an invalid authentication.
      *
      * @param string $type  The type of error (self::REASON_* constant).
index d3dbf6d..0e017f0 100644 (file)
@@ -53,6 +53,7 @@ class Horde_Core_Binder_SessionHandler implements Horde_Injector_Binder
         }
 
         $params['logger'] = $logger;
+        $params['parse'] = array($this, 'readSessionData');
 
         return Horde_SessionHandler::factory($driver, $params);
     }
@@ -61,4 +62,45 @@ class Horde_Core_Binder_SessionHandler implements Horde_Injector_Binder
     {
         return false;
     }
+
+    /**
+     * Reads session data to determine if it contains Horde authentication
+     * credentials.
+     *
+     * @param string $session_data  The session data.
+     *
+     * @return array  An array of the user's sesion information if
+     *                authenticated or false.  The following information is
+     *                returned: userid, timestamp, remoteAddr, browser, apps.
+     */
+    public function readSessionData($session_data)
+    {
+        if (empty($session_data) ||
+            (($pos = strpos($session_data, 'horde_auth|')) === false)) {
+            return false;
+        }
+
+        $pos += 11;
+        $endpos = $pos + 1;
+
+        while ($endpos !== false) {
+            $endpos = strpos($session_data, '|', $endpos);
+            $data = @unserialize(substr($session_data, $pos, $endpos));
+            if (is_array($data)) {
+                return empty($data)
+                    ? false
+                    : array(
+                        'apps' => empty($data['app']) ? array('horde') : array_keys($data['app']),
+                        'browser' => $data['browser'],
+                        'remoteAddr' => $data['remoteAddr'],
+                        'timestamp' => $data['timestamp'],
+                        'userid' => $data['userId']
+                    );
+            }
+            ++$endpos;
+        }
+
+        return false;
+    }
+
 }
index fa78adc..04bb041 100644 (file)
@@ -65,6 +65,11 @@ abstract class Horde_SessionHandler_Driver
      *            DEFAULT: No logging
      * 'noset' - (boolean) If true, don't set the save handler.
      *           DEFAULT: false
+     * 'parse' - (callback) A callback function that parses session
+     *           information into an array. Is passed the raw session data
+     *           as the only argument; expects either false or an array of
+     *           session data as a return.
+     *           DEFAULT: No
      * </pre>
      */
     public function __construct(array $params = array())
@@ -293,23 +298,29 @@ abstract class Horde_SessionHandler_Driver
      * Returns a list of authenticated users and data about their session.
      *
      * @return array  For authenticated users, the sessionid as a key and the
-     *                information returned from Horde_Auth::readSessionData()
-     *                as values.
+     *                session information as value. If no parsing function
+     *                was provided, will always return an empty array.
      * @throws Horde_SessionHandler_Exception
      */
     public function getSessionsInfo()
     {
-        $sessions = $this->getSessionIDs();
-
         $info = array();
 
+        if (empty($this->_params['parse']) ||
+            !is_callable($this->_params['parse'])) {
+            return $info;
+        }
+
+        $sessions = $this->getSessionIDs();
+
         foreach ($sessions as $id) {
             try {
                 $data = $this->_readOnly($id);
             } catch (Horde_SessionHandler_Exception $e) {
                 continue;
             }
-            $data = Horde_Auth::readSessionData($data, true);
+
+            $data = call_user_func($this->_params['parse'], $data);
             if ($data !== false) {
                 $info[$id] = $data;
             }
index 2e5d5e1..2caac1b 100644 (file)
   </required>
   <optional>
    <package>
-    <name>Auth</name>
-    <channel>pear.horde.org</channel>
-   </package>
-   <package>
     <name>Db</name>
     <channel>pear.horde.org</channel>
    </package>