From d36abc878b38c33eacd718cfd86a173800f9f3c0 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 12 Nov 2010 13:22:14 -0700 Subject: [PATCH] Abstract storage portion of sessionhandler into a separate class --- .../Core/lib/Horde/Core/Factory/SessionHandler.php | 78 +++++++------ .../SessionHandler/lib/Horde/SessionHandler.php | 95 ++++++---------- .../lib/Horde/SessionHandler/External.php | 125 --------------------- .../lib/Horde/SessionHandler/Storage.php | 124 ++++++++++++++++++++ .../Horde/SessionHandler/{ => Storage}/Builtin.php | 59 ++-------- .../lib/Horde/SessionHandler/Storage/External.php | 96 ++++++++++++++++ .../SessionHandler/{ => Storage}/Memcache.php | 71 ++---------- .../lib/Horde/SessionHandler/{ => Storage}/Sql.php | 60 +++++----- .../Horde/SessionHandler/{ => Storage}/Stack.php | 87 +++++--------- framework/SessionHandler/package.xml | 26 +++-- 10 files changed, 385 insertions(+), 436 deletions(-) delete mode 100644 framework/SessionHandler/lib/Horde/SessionHandler/External.php create mode 100644 framework/SessionHandler/lib/Horde/SessionHandler/Storage.php rename framework/SessionHandler/lib/Horde/SessionHandler/{ => Storage}/Builtin.php (51%) create mode 100644 framework/SessionHandler/lib/Horde/SessionHandler/Storage/External.php rename framework/SessionHandler/lib/Horde/SessionHandler/{ => Storage}/Memcache.php (75%) rename framework/SessionHandler/lib/Horde/SessionHandler/{ => Storage}/Sql.php (77%) rename framework/SessionHandler/lib/Horde/SessionHandler/{ => Storage}/Stack.php (51%) diff --git a/framework/Core/lib/Horde/Core/Factory/SessionHandler.php b/framework/Core/lib/Horde/Core/Factory/SessionHandler.php index c65d48b1a..927e82f22 100644 --- a/framework/Core/lib/Horde/Core/Factory/SessionHandler.php +++ b/framework/Core/lib/Horde/Core/Factory/SessionHandler.php @@ -35,53 +35,57 @@ class Horde_Core_Factory_SessionHandler } $params = Horde::getDriverConfig('sessionhandler', $driver); - if (strcasecmp($driver, 'Sql') === 0) { - $params['db'] = $injector->getInstance('Horde_Db_Adapter'); - } elseif (strcasecmp($driver, 'Memcache') === 0) { - $params['memcache'] = $injector->getInstance('Horde_Memcache'); - } elseif (strcasecmp($driver, 'Ldap') === 0) { + $driver = basename(Horde_String::lower($driver)); + $noset = false; + + switch ($driver) { + case 'builtin': + $noset = true; + break; + + case 'ldap': $params['ldap'] = $injector->getInstances('Horde_Core_Factory_Ldap')->getLdap('horde', 'sessionhandler'); + break; + + case 'memcache': + $params['memcache'] = $injector->getInstance('Horde_Memcache'); + break; + + case 'sql': + $params['db'] = $injector->getInstance('Horde_Db_Adapter'); + break; } - $logger = $injector->getInstance('Horde_Log_Logger'); + $class = 'Horde_SessionHandler_Storage_' . Horde_String::ucfirst($driver); + if (!class_exists($class)) { + throw new Horde_SessionHandler_Exception('Driver not found: ' . $class); + } + $storage = new $class($params); if (!empty($conf['sessionhandler']['memcache']) && - (strcasecmp($driver, 'Builtin') != 0) && - (strcasecmp($driver, 'Memcache') != 0)) { - $params = array( + !in_array($driver, array('builtin', 'memcache'))) { + $storage = new Horde_SessionHandler_Storage_Stack(array( 'stack' => array( - array( - 'driver' => 'Memcache', - 'params' => array( - 'memcache' => $injector->getInstance('Horde_Memcache'), - 'logger' => $logger - ) - ), - array( - 'driver' => $driver, - 'params' => array_merge($params, array( - 'logger' => $logger - )) - ) + new Horde_SessionHandler_Storage_Memcache(array( + 'memcache' => $injector->getInstance('Horde_Memcache') + )), + $storage ) - ); - $driver = 'Stack'; + )); } - $params['logger'] = $logger; - // TODO: Uncomment once all session data is saved through - // Horde_Session. - //$params['no_md5'] = true - $params['parse'] = array($this, 'readSessionData'); - - $driver = basename(strtolower($driver)); - $class = 'Horde_SessionHandler_' . ucfirst($driver); - - if (class_exists($class)) { - return new $class($params); - } - throw new Horde_SessionHandler_Exception('Driver not found: ' . $driver); + return new Horde_SessionHandler( + $storage, + array( + 'logger' => $injector->getInstance('Horde_Log_Logger'), + // TODO: Uncomment once all session data is saved through + // Horde_Session. + //'no_md5' => true, + 'noset' => $noset, + 'parse' => array($this, 'readSessionData') + ) + ); } /** diff --git a/framework/SessionHandler/lib/Horde/SessionHandler.php b/framework/SessionHandler/lib/Horde/SessionHandler.php index a943715ef..696e23191 100644 --- a/framework/SessionHandler/lib/Horde/SessionHandler.php +++ b/framework/SessionHandler/lib/Horde/SessionHandler.php @@ -1,6 +1,6 @@ * logger - (Horde_Log_Logger) A logger instance. * DEFAULT: No logging @@ -70,16 +78,20 @@ abstract class Horde_SessionHandler * DEFAULT: No * */ - public function __construct(array $params = array()) + public function __construct(Horde_SessionHandler_Storage $storage, + array $params = array()) { $params = array_merge($this->_params, $params); if (isset($params['logger'])) { $this->_logger = $params['logger']; unset($params['logger']); + + $storage->setLogger($this->_logger); } $this->_params = $params; + $this->_storage = $storage; if (empty($this->_params['noset'])) { ini_set('session.save_handler', 'user'); @@ -117,7 +129,7 @@ abstract class Horde_SessionHandler { if (!$this->_connected) { try { - $this->_open($save_path, $session_name); + $this->_storage->open($save_path, $session_name); } catch (Horde_SessionHandler_Exception $e) { if ($this->_logger) { $this->_logger->log($e, 'ERR'); @@ -132,16 +144,6 @@ abstract class Horde_SessionHandler } /** - * Open the backend. - * - * @param string $save_path The path to the session object. - * @param string $session_name The name of the session. - * - * @throws Horde_SessionHandler_Exception - */ - abstract protected function _open($save_path = null, $session_name = null); - - /** * Close the backend. * * @return boolean True on success, false otherwise. @@ -149,7 +151,7 @@ abstract class Horde_SessionHandler public function close() { try { - $this->_close(); + $this->_storage->close(); } catch (Horde_SessionHandler_Exception $e) { if ($this->_logger) { $this->_logger->log($e, 'ERR'); @@ -162,13 +164,6 @@ abstract class Horde_SessionHandler } /** - * Close the backend. - * - * @throws Horde_SessionHandler_Exception - */ - abstract protected function _close(); - - /** * Read the data for a particular session identifier from the backend. * This method should only be called internally by PHP via * session_set_save_handler(). @@ -179,7 +174,7 @@ abstract class Horde_SessionHandler */ public function read($id) { - $result = $this->_read($id); + $result = $this->_storage->read($id); if (empty($this->_params['no_md5'])) { $this->_sig = md5($result); } @@ -187,15 +182,6 @@ abstract class Horde_SessionHandler } /** - * Read the data for a particular session identifier from the backend. - * - * @param string $id The session identifier. - * - * @return string The session data. - */ - abstract protected function _read($id); - - /** * Write session data to the backend. * This method should only be called internally by PHP via * session_set_save_handler(). @@ -210,7 +196,7 @@ abstract class Horde_SessionHandler if ($this->changed || (empty($this->_params['no_md5']) && ($this->_sig != md5($session_data)))) { - return $this->_write($id, $session_data); + return $this->_storage->write($id, $session_data); } if ($this->_logger) { @@ -221,16 +207,6 @@ abstract class Horde_SessionHandler } /** - * Write session data to the backend. - * - * @param string $id The session identifier. - * @param string $session_data The session data. - * - * @return boolean True on success, false otherwise. - */ - abstract protected function _write($id, $session_data); - - /** * Destroy the data for a particular session identifier in the backend. * This method should only be called internally by PHP via * session_set_save_handler(). @@ -239,7 +215,10 @@ abstract class Horde_SessionHandler * * @return boolean True on success, false otherwise. */ - abstract public function destroy($id); + public function destroy($id) + { + return $this->_storage->destroy($id); + } /** * Garbage collect stale sessions from the backend. @@ -250,18 +229,9 @@ abstract class Horde_SessionHandler * * @return boolean True on success, false otherwise. */ - abstract public function gc($maxlifetime = 300); - - /** - * Get session data read-only. - * - * @param string $id The session identifier. - * - * @return string The session data. - */ - protected function _readOnly($id) + public function gc($maxlifetime = 300) { - return $this->read($id); + return $this->_storage->gc($id); } /** @@ -270,7 +240,10 @@ abstract class Horde_SessionHandler * @return array A list of valid session identifiers. * @throws Horde_SessionHandler_Exception */ - abstract public function getSessionIDs(); + public function getSessionIDs() + { + return $this->_storage->getSessionIDs(); + } /** * Returns a list of authenticated users and data about their session. @@ -291,9 +264,11 @@ abstract class Horde_SessionHandler $sessions = $this->getSessionIDs(); + $this->_storage->readonly = true; + foreach ($sessions as $id) { try { - $data = $this->_readOnly($id); + $data = $this->read($id); } catch (Horde_SessionHandler_Exception $e) { continue; } @@ -304,6 +279,8 @@ abstract class Horde_SessionHandler } } + $this->_storage->readonly = false; + return $info; } diff --git a/framework/SessionHandler/lib/Horde/SessionHandler/External.php b/framework/SessionHandler/lib/Horde/SessionHandler/External.php deleted file mode 100644 index 414e31071..000000000 --- a/framework/SessionHandler/lib/Horde/SessionHandler/External.php +++ /dev/null @@ -1,125 +0,0 @@ - - * @category Horde - * @package SessionHandler - */ -class Horde_SessionHandler_External extends Horde_SessionHandler -{ - /** - * Constructor. - * - * @param array $params Required parameters: - *
-     * 'close' - (callback) See session_set_save_handler().
-     * 'destroy' - (callback) See session_set_save_handler().
-     * 'gc' - (callback) See session_set_save_handler().
-     * 'open' - (callback) See session_set_save_handler().
-     * 'read' - (callback) See session_set_save_handler().
-     * 'write' - (callback) See session_set_save_handler().
-     * 
- * - * @throws InvalidArgumentException - */ - public function __construct(array $params = array()) - { - foreach (array('open', 'close', 'read', 'write', 'destroy', 'gc') as $val) { - if (!isset($params[$val])) { - throw new InvalidArgumentException('Missing parameter: ' . $val); - } - } - - parent::__construct($params); - } - - /** - * Open the backend. - * - * @param string $save_path The path to the session object. - * @param string $session_name The name of the session. - */ - protected function _open($save_path = null, $session_name = null) - { - call_user_func($this->_params['open'], $save_path, $session_name); - } - - /** - * Close the backend. - */ - protected function _close() - { - call_user_func($this->_params['close']); - } - - /** - * Read the data for a particular session identifier from the backend. - * - * @param string $id The session identifier. - * - * @return string The session data. - */ - protected function _read($id) - { - return call_user_func($this->_params['read']); - } - - /** - * Write session data to the backend. - * - * @param string $id The session identifier. - * @param string $session_data The session data. - * - * @return boolean True on success, false otherwise. - */ - protected function _write($id, $session_data) - { - return call_user_func($this->_params['write'], $id, $session_data); - } - - /** - * Destroy the data for a particular session identifier in the backend. - * This method should only be called internally by PHP via - * session_set_save_handler(). - * - * @param string $id The session identifier. - * - * @return boolean True on success, false otherwise. - */ - public function destroy($id) - { - return call_user_func($this->_params['destroy'], $id); - } - - /** - * Garbage collect stale sessions from the backend. - * This method should only be called internally by PHP via - * session_set_save_handler(). - * - * @param integer $maxlifetime The maximum age of a session. - * - * @return boolean True on success, false otherwise. - */ - public function gc($maxlifetime = 300) - { - return call_user_func($this->_params['gc'], $maxlifetime); - } - - /** - * Get a list of the valid session identifiers. - * - * @throws Horde_SessionHandler_Exception - */ - public function getSessionIDs() - { - throw new Horde_SessionHandler_Exception('Driver does not support listing session IDs.'); - } - -} diff --git a/framework/SessionHandler/lib/Horde/SessionHandler/Storage.php b/framework/SessionHandler/lib/Horde/SessionHandler/Storage.php new file mode 100644 index 000000000..78fe885b1 --- /dev/null +++ b/framework/SessionHandler/lib/Horde/SessionHandler/Storage.php @@ -0,0 +1,124 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package SessionHandler + */ +abstract class Horde_SessionHandler_Storage +{ + /** + * Access session read-only? + * + * @var boolean + */ + public $readonly = false; + + /** + * A logger instance. + * + * @var Horde_Log_Logger + */ + protected $_logger; + + /** + * Hash containing connection parameters. + * + * @var array + */ + protected $_params = array(); + + /** + * Constructor. + * + * @param array $params Configuration parameters. + */ + public function __construct(array $params = array()) + { + $params = array_merge($this->_params, $params); + } + + /** + * Set the logger object. + * + * @param Horde_Log_Logger $log The logger instance. + */ + public function setLogger(Horde_Log_Logger $log) + { + $this->_logger = $log; + } + + /** + * Open the backend. + * + * @param string $save_path The path to the session object. + * @param string $session_name The name of the session. + * + * @throws Horde_SessionHandler_Exception + */ + abstract public function open($save_path = null, $session_name = null); + + /** + * Close the backend. + * + * @throws Horde_SessionHandler_Exception + */ + abstract public function close(); + + /** + * Read the data for a particular session identifier from the backend. + * + * @param string $id The session identifier. + * + * @return string The session data. + */ + abstract public function read($id); + + /** + * Write session data to the backend. + * + * @param string $id The session identifier. + * @param string $session_data The session data. + * + * @return boolean True on success, false otherwise. + */ + abstract public function write($id, $session_data); + + /** + * Destroy the data for a particular session identifier in the backend. + * This method should only be called internally by PHP via + * session_set_save_handler(). + * + * @param string $id The session identifier. + * + * @return boolean True on success, false otherwise. + */ + abstract public function destroy($id); + + /** + * Garbage collect stale sessions from the backend. + * This method should only be called internally by PHP via + * session_set_save_handler(). + * + * @param integer $maxlifetime The maximum age of a session. + * + * @return boolean True on success, false otherwise. + */ + abstract public function gc($maxlifetime = 300); + + /** + * Get a list of the valid session identifiers. + * + * @return array A list of valid session identifiers. + * @throws Horde_SessionHandler_Exception + */ + abstract public function getSessionIDs(); + +} diff --git a/framework/SessionHandler/lib/Horde/SessionHandler/Builtin.php b/framework/SessionHandler/lib/Horde/SessionHandler/Storage/Builtin.php similarity index 51% rename from framework/SessionHandler/lib/Horde/SessionHandler/Builtin.php rename to framework/SessionHandler/lib/Horde/SessionHandler/Storage/Builtin.php index 72a77d093..5bf7477d5 100644 --- a/framework/SessionHandler/lib/Horde/SessionHandler/Builtin.php +++ b/framework/SessionHandler/lib/Horde/SessionHandler/Storage/Builtin.php @@ -1,6 +1,6 @@ * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @package SessionHandler */ -class Horde_SessionHandler_Builtin extends Horde_SessionHandler +class Horde_SessionHandler_Storage_Builtin extends Horde_SessionHandler_Storage { /** * Directory with session files. @@ -23,15 +24,10 @@ class Horde_SessionHandler_Builtin extends Horde_SessionHandler protected $_path; /** - * Constructor. - * - * @param array $params Parameters. */ public function __construct(array $params = array()) { - parent::__construct(array_merge($params, array( - 'noset' => true - ))); + parent::__construct($params); $this->_path = session_save_path(); if (!$this->_path) { @@ -40,32 +36,20 @@ class Horde_SessionHandler_Builtin extends Horde_SessionHandler } /** - * Open the backend. - * - * @param string $save_path The path to the session object. - * @param string $session_name The name of the session. */ - protected function _open($save_path = null, $session_name = null) - { - } + public function open($save_path = null, $session_name = null) + { + } /** - * Close the backend. - * - * @throws Horde_Exception */ - protected function _close() + public function close() { } /** - * Read the data for a particular session identifier from the backend. - * - * @param string $id The session identifier. - * - * @return string The session data. */ - protected function _read($id) + public function read($id) { $file = $this->_path . '/sess_' . $id; $session_data = @file_get_contents($file); @@ -77,26 +61,13 @@ class Horde_SessionHandler_Builtin extends Horde_SessionHandler } /** - * Write session data to the backend. - * - * @param string $id The session identifier. - * @param string $session_data The session data. - * - * @return boolean True on success, false otherwise. */ - protected function _write($id, $session_data) + public function write($id, $session_data) { return false; } /** - * Destroy the data for a particular session identifier in the backend. - * This method should only be called internally by PHP via - * session_set_save_handler(). - * - * @param string $id The session identifier. - * - * @return boolean True on success, false otherwise. */ public function destroy($id) { @@ -104,13 +75,6 @@ class Horde_SessionHandler_Builtin extends Horde_SessionHandler } /** - * Garbage collect stale sessions from the backend. - * This method should only be called internally by PHP via - * session_set_save_handler(). - * - * @param integer $maxlifetime The maximum age of a session. - * - * @return boolean True on success, false otherwise. */ public function gc($maxlifetime = 300) { @@ -118,9 +82,6 @@ class Horde_SessionHandler_Builtin extends Horde_SessionHandler } /** - * Get a list of the valid session identifiers. - * - * @return array A list of valid session identifiers. */ public function getSessionIDs() { diff --git a/framework/SessionHandler/lib/Horde/SessionHandler/Storage/External.php b/framework/SessionHandler/lib/Horde/SessionHandler/Storage/External.php new file mode 100644 index 000000000..7731921f8 --- /dev/null +++ b/framework/SessionHandler/lib/Horde/SessionHandler/Storage/External.php @@ -0,0 +1,96 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package SessionHandler + */ +class Horde_SessionHandler_Storage_External extends Horde_SessionHandler_Storage +{ + /** + * Constructor. + * + * @param array $params Required parameters: + *
+     * close - (callback) See session_set_save_handler().
+     * destroy - (callback) See session_set_save_handler().
+     * gc - (callback) See session_set_save_handler().
+     * open - (callback) See session_set_save_handler().
+     * read - (callback) See session_set_save_handler().
+     * write - (callback) See session_set_save_handler().
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct(array $params = array()) + { + foreach (array('open', 'close', 'read', 'write', 'destroy', 'gc') as $val) { + if (!isset($params[$val])) { + throw new InvalidArgumentException('Missing parameter: ' . $val); + } + } + + parent::__construct($params); + } + + /** + */ + public function open($save_path = null, $session_name = null) + { + call_user_func($this->_params['open'], $save_path, $session_name); + } + + /** + */ + public function close() + { + call_user_func($this->_params['close']); + } + + /** + */ + public function read($id) + { + return call_user_func($this->_params['read']); + } + + /** + */ + public function write($id, $session_data) + { + return call_user_func($this->_params['write'], $id, $session_data); + } + + /** + */ + public function destroy($id) + { + return call_user_func($this->_params['destroy'], $id); + } + + /** + */ + public function gc($maxlifetime = 300) + { + return call_user_func($this->_params['gc'], $maxlifetime); + } + + /** + * Get a list of the valid session identifiers. + * + * @throws Horde_SessionHandler_Exception + */ + public function getSessionIDs() + { + throw new Horde_SessionHandler_Exception('Driver does not support listing session IDs.'); + } + +} diff --git a/framework/SessionHandler/lib/Horde/SessionHandler/Memcache.php b/framework/SessionHandler/lib/Horde/SessionHandler/Storage/Memcache.php similarity index 75% rename from framework/SessionHandler/lib/Horde/SessionHandler/Memcache.php rename to framework/SessionHandler/lib/Horde/SessionHandler/Storage/Memcache.php index 34344b7d7..9dd1c28c4 100644 --- a/framework/SessionHandler/lib/Horde/SessionHandler/Memcache.php +++ b/framework/SessionHandler/lib/Horde/SessionHandler/Storage/Memcache.php @@ -12,7 +12,7 @@ * @category Horde * @package SessionHandler */ -class Horde_SessionHandler_Memcache extends Horde_SessionHandler +class Horde_SessionHandler_Storage_Memcache extends Horde_SessionHandler_Storage { /** * Memcache object. @@ -29,13 +29,6 @@ class Horde_SessionHandler_Memcache extends Horde_SessionHandler protected $_id; /** - * Do read-only get? - * - * @var boolean - */ - protected $_readonly = false; - - /** * The ID used for session tracking. * * @var string @@ -76,21 +69,14 @@ class Horde_SessionHandler_Memcache extends Horde_SessionHandler } /** - * Open the backend. - * - * @param string $save_path The path to the session object. - * @param string $session_name The name of the session. - * - * @throws Horde_SessionHandler_Exception */ - protected function _open($save_path = null, $session_name = null) + public function open($save_path = null, $session_name = null) { } /** - * Close the backend. */ - protected function _close() + public function close() { if (isset($this->_id)) { $this->_memcache->unlock($this->_id); @@ -98,21 +84,16 @@ class Horde_SessionHandler_Memcache extends Horde_SessionHandler } /** - * Read the data for a particular session identifier. - * - * @param string $id The session identifier. - * - * @return string The session data. */ - protected function _read($id) + public function read($id) { - if (!$this->_readonly) { + if (!$this->readonly) { $this->_memcache->lock($id); } $result = $this->_memcache->get($id); if ($result === false) { - if (!$this->_readonly) { + if (!$this->readonly) { $this->_memcache->unlock($id); } @@ -124,7 +105,7 @@ class Horde_SessionHandler_Memcache extends Horde_SessionHandler } } - if (!$this->_readonly) { + if (!$this->readonly) { $this->_id = $id; } @@ -136,14 +117,8 @@ class Horde_SessionHandler_Memcache extends Horde_SessionHandler } /** - * Write session data to the backend. - * - * @param string $id The session identifier. - * @param string $session_data The session data. - * - * @return boolean True on success, false otherwise. */ - protected function _write($id, $session_data) + public function write($id, $session_data) { if (!empty($this->_params['track'])) { // Do a replace - the only time it should fail is if we are @@ -183,11 +158,6 @@ class Horde_SessionHandler_Memcache extends Horde_SessionHandler } /** - * Destroy the data for a particular session identifier. - * - * @param string $id The session identifier. - * - * @return boolean True on success, false otherwise. */ public function destroy($id) { @@ -219,11 +189,6 @@ class Horde_SessionHandler_Memcache extends Horde_SessionHandler } /** - * Garbage collect stale sessions from the backend. - * - * @param integer $maxlifetime The maximum age of a session. - * - * @return boolean True on success, false otherwise. */ public function gc($maxlifetime = 300) { @@ -232,10 +197,6 @@ class Horde_SessionHandler_Memcache extends Horde_SessionHandler } /** - * Get a list of (possibly) valid session identifiers. - * - * @return array A list of session identifiers. - * @throws Horde_SessionHandler_Exception */ public function getSessionIDs() { @@ -253,22 +214,6 @@ class Horde_SessionHandler_Memcache extends Horde_SessionHandler } /** - * Get session data read-only. - * - * @param string $id The session identifier. - * - * @return string The session data. - */ - protected function _readOnly($id) - { - $this->_readonly = true; - $result = $this->_memcache->get($id); - $this->_readonly = false; - - return $result; - } - - /** * Do garbage collection for session tracking information. */ public function trackGC() diff --git a/framework/SessionHandler/lib/Horde/SessionHandler/Sql.php b/framework/SessionHandler/lib/Horde/SessionHandler/Storage/Sql.php similarity index 77% rename from framework/SessionHandler/lib/Horde/SessionHandler/Sql.php rename to framework/SessionHandler/lib/Horde/SessionHandler/Storage/Sql.php index bf8839b99..39cda3c69 100644 --- a/framework/SessionHandler/lib/Horde/SessionHandler/Sql.php +++ b/framework/SessionHandler/lib/Horde/SessionHandler/Storage/Sql.php @@ -1,9 +1,21 @@ + * CREATE TABLE horde_sessionhandler ( + * VARCHAR(32) NOT NULL, + * session_lastmodified INT NOT NULL, + * session_data LONGBLOB, + * -- Or, on some DBMS systems: + * -- session_data IMAGE, + * + * PRIMARY KEY (session_id) + * ); + * + * CREATE INDEX session_lastmodified_idx ON horde_sessionhandler (session_lastmodified); + * * * Copyright 2002-2010 The Horde Project (http://www.horde.org/) * @@ -12,9 +24,10 @@ * * @author Mike Cochrane * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @package SessionHandler */ -class Horde_SessionHandler_Sql extends Horde_SessionHandler +class Horde_SessionHandler_Storage_Sql extends Horde_SessionHandler_Storage { /** * Handle for the current database connection. @@ -49,11 +62,14 @@ class Horde_SessionHandler_Sql extends Horde_SessionHandler } /** - * Close the backend. - * - * @throws Horde_SessionHandler_Exception */ - protected function _close() + public function open($save_path = null, $session_name = null) + { + } + + /** + */ + public function close() { /* Close any open transactions. */ try { @@ -64,13 +80,8 @@ class Horde_SessionHandler_Sql extends Horde_SessionHandler } /** - * Read the data for a particular session identifier from the backend. - * - * @param string $id The session identifier. - * - * @return string The session data. */ - protected function _read($id) + public function read($id) { /* Begin a transaction. */ // TODO: Rowlocking in Mysql @@ -90,14 +101,8 @@ class Horde_SessionHandler_Sql extends Horde_SessionHandler } /** - * Write session data to the backend. - * - * @param string $id The session identifier. - * @param string $session_data The session data. - * - * @return boolean True on success, false otherwise. */ - protected function _write($id, $session_data) + public function write($id, $session_data) { /* Build the SQL query. */ $query = sprintf('SELECT session_id FROM %s WHERE session_id = ?', @@ -135,11 +140,6 @@ class Horde_SessionHandler_Sql extends Horde_SessionHandler } /** - * Destroy the data for a particular session identifier in the backend. - * - * @param string $id The session identifier. - * - * @return boolean True on success, false otherwise. */ public function destroy($id) { @@ -160,11 +160,6 @@ class Horde_SessionHandler_Sql extends Horde_SessionHandler } /** - * Garbage collect stale sessions from the backend. - * - * @param integer $maxlifetime The maximum age of a session. - * - * @return boolean True on success, false otherwise. */ public function gc($maxlifetime = 300) { @@ -184,9 +179,6 @@ class Horde_SessionHandler_Sql extends Horde_SessionHandler } /** - * Get a list of the valid session identifiers. - * - * @return array A list of valid session identifiers. */ public function getSessionIDs() { diff --git a/framework/SessionHandler/lib/Horde/SessionHandler/Stack.php b/framework/SessionHandler/lib/Horde/SessionHandler/Storage/Stack.php similarity index 51% rename from framework/SessionHandler/lib/Horde/SessionHandler/Stack.php rename to framework/SessionHandler/lib/Horde/SessionHandler/Storage/Stack.php index 0050257e0..b3f0e568b 100644 --- a/framework/SessionHandler/lib/Horde/SessionHandler/Stack.php +++ b/framework/SessionHandler/lib/Horde/SessionHandler/Storage/Stack.php @@ -1,9 +1,9 @@ * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL * @package SessionHandler */ -class Horde_SessionHandler_Stack extends Horde_SessionHandler +class Horde_SessionHandler_Storage_Stack extends Horde_SessionHandler_Storage { /** - * Stack of sessionhandlers. + * Stack of storage objects. * - * @var string + * @var array */ protected $_stack = array(); @@ -28,12 +29,9 @@ class Horde_SessionHandler_Stack extends Horde_SessionHandler * * @param array $params Parameters: *
-     * 'stack' - (array) [REQUIRED] A list of sessionhandlers to loop
-     *           through, in order of priority. The last entry is considered
-     *           the "master" server.
-     *           Each value should contain an array with two keys: 'driver', a
-     *           string value with the SessionHandler driver to use, and
-     *           'params', containing any parameters needed by this driver.
+     * stack - (array) [REQUIRED] A list of storage objects to loop
+     *         through, in order of priority. The last entry is considered
+     *         the "master" server.
      * 
* * @throws InvalidArgumentException @@ -44,24 +42,29 @@ class Horde_SessionHandler_Stack extends Horde_SessionHandler throw new InvalidArgumentException('Missing stack parameter.'); } - foreach ($params['stack'] as $val) { - $this->_stack[] = Horde_SessionHandler::factory($val['driver'], $val['params']); - } - + $this->_stack = $params['stack']; unset($params['stack']); parent::__construct($params); } /** - * Open the backend. - * - * @param string $save_path The path to the session object. - * @param string $session_name The name of the session. + * Set the logger object. * - * @throws Horde_SessionHandler_Exception + * @param Horde_Log_Logger $log The logger instance. + */ + public function setLogger(Horde_Log_Logger $log) + { + parent::setLogger($log); + + foreach ($this->_stack as $ob) { + $ob->setLogger($log); + } + } + + /** */ - protected function _open($save_path = null, $session_name = null) + public function open($save_path = null, $session_name = null) { foreach ($this->_stack as $val) { $val->open($save_path, $session_name); @@ -69,11 +72,8 @@ class Horde_SessionHandler_Stack extends Horde_SessionHandler } /** - * Close the backend. - * - * @throws Horde_SessionHandler_Exception */ - protected function _close() + public function close() { foreach ($this->_stack as $val) { $val->close(); @@ -81,13 +81,8 @@ class Horde_SessionHandler_Stack extends Horde_SessionHandler } /** - * Read the data for a particular session identifier from the backend. - * - * @param string $id The session identifier. - * - * @return string The session data. */ - protected function _read($id) + public function read($id) { foreach ($this->_stack as $val) { $result = $val->read($id); @@ -100,14 +95,8 @@ class Horde_SessionHandler_Stack extends Horde_SessionHandler } /** - * Write session data to the backend. - * - * @param string $id The session identifier. - * @param string $session_data The session data. - * - * @return boolean True on success, false otherwise. */ - protected function _write($id, $session_data) + public function write($id, $session_data) { /* Do writes in *reverse* order - it is OK if a write to one of the * non-master backends fails. */ @@ -129,13 +118,6 @@ class Horde_SessionHandler_Stack extends Horde_SessionHandler } /** - * Destroy the data for a particular session identifier in the backend. - * This method should only be called internally by PHP via - * session_set_save_handler(). - * - * @param string $id The session identifier. - * - * @return boolean True on success, false otherwise. */ public function destroy($id) { @@ -154,13 +136,6 @@ class Horde_SessionHandler_Stack extends Horde_SessionHandler } /** - * Garbage collect stale sessions from the backend. - * This method should only be called internally by PHP via - * session_set_save_handler(). - * - * @param integer $maxlifetime The maximum age of a session. - * - * @return boolean True on success, false otherwise. */ public function gc($maxlifetime = 300) { @@ -173,10 +148,6 @@ class Horde_SessionHandler_Stack extends Horde_SessionHandler } /** - * Get a list of the valid session identifiers. - * - * @return array A list of valid session identifiers. - * @throws Horde_SessionHandler_Exception */ public function getSessionIDs() { diff --git a/framework/SessionHandler/package.xml b/framework/SessionHandler/package.xml index 4a0295b91..e86b7ff6c 100644 --- a/framework/SessionHandler/package.xml +++ b/framework/SessionHandler/package.xml @@ -34,7 +34,7 @@ beta LGPL - + * Abstracted storage-specific code into 'Storage' drivers. * Removed LDAP driver * Abstracted memcache persistent-backend code into 'Stack' driver. * Renamed 'none' driver to 'Builtin'. @@ -50,12 +50,15 @@ - + + + + + + + - - - - + @@ -97,12 +100,13 @@ - + + + + + - - - - + -- 2.11.0