From: Michael M Slusarz Date: Fri, 12 Nov 2010 20:49:50 +0000 (-0700) Subject: Add Horde_SessionHandler_Storage_File X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=f2ff042a78bad7c3c915e60576f9c1870a74e251;p=horde.git Add Horde_SessionHandler_Storage_File --- diff --git a/framework/SessionHandler/lib/Horde/SessionHandler/Storage.php b/framework/SessionHandler/lib/Horde/SessionHandler/Storage.php index 78fe885b1..05290b851 100644 --- a/framework/SessionHandler/lib/Horde/SessionHandler/Storage.php +++ b/framework/SessionHandler/lib/Horde/SessionHandler/Storage.php @@ -42,7 +42,7 @@ abstract class Horde_SessionHandler_Storage */ public function __construct(array $params = array()) { - $params = array_merge($this->_params, $params); + $this->_params = array_merge($this->_params, $params); } /** diff --git a/framework/SessionHandler/lib/Horde/SessionHandler/Storage/File.php b/framework/SessionHandler/lib/Horde/SessionHandler/Storage/File.php new file mode 100644 index 000000000..6cc7f5baa --- /dev/null +++ b/framework/SessionHandler/lib/Horde/SessionHandler/Storage/File.php @@ -0,0 +1,122 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package SessionHandler + */ +class Horde_SessionHandler_Storage_File extends Horde_SessionHandler_Storage +{ + const PREFIX = 'horde_sh_'; + + /** + * Constructor. + * + * @param array $params Parameters: + *
+     * path - (string) [REQUIRED] The path to save the files.
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct(array $params = array()) + { + if (!isset($params['path'])) { + throw new InvalidArgumentException('Missing path parameter.'); + } + $params['path'] = rtrim($params['path'], '/'); + + parent::__construct($params); + } + + /** + */ + public function open($save_path = null, $session_name = null) + { + } + + /** + */ + public function close() + { + } + + /** + */ + public function read($id) + { + $filename = $this->_params['path'] . '/' . self::PREFIX . $id; + + return file_exists($filename) + ? file_get_contents($filename) + : ''; + } + + /** + */ + public function write($id, $session_data) + { + $filename = $this->_params['path'] . '/' . self::PREFIX . $id; + + return @file_put_contents($filename, $session_data); + } + + /** + */ + public function destroy($id) + { + $filename = $this->_params['path'] . '/' . self::PREFIX . $id; + + return @unlink($filename); + } + + /** + */ + public function gc($maxlifetime = 300) + { + try { + $di = new DirectoryIterator($this->_params['path']); + } catch (UnexpectedValueException $e) { + return false; + } + + $expire_time = time() - $maxlifetime; + + foreach ($di as $val) { + if ($val->isFile() && + (strpos($val->getFilename(), self::PREFIX) === 0) && + ($val->getMTime() < $expire_time)) { + @unlink($val->getPathname()); + } + } + + return true; + } + + /** + */ + public function getSessionIDs() + { + $ids = array(); + + try { + $di = new DirectoryIterator($this->_params['path']); + foreach ($di as $val) { + if ($val->isFile() && + (strpos($val->getFilename(), self::PREFIX) === 0)) { + $ids[] = substr($val->getFilename(), strlen(self::PREFIX)); + } + } + } catch (UnexpectedValueException $e) {} + + return $ids; + } + +} diff --git a/framework/SessionHandler/package.xml b/framework/SessionHandler/package.xml index e86b7ff6c..8cf41b8a5 100644 --- a/framework/SessionHandler/package.xml +++ b/framework/SessionHandler/package.xml @@ -34,7 +34,8 @@ beta LGPL - * Abstracted storage-specific code into 'Storage' drivers. + * Added 'File' driver. +* Abstracted storage-specific code into 'Storage' drivers. * Removed LDAP driver * Abstracted memcache persistent-backend code into 'Stack' driver. * Renamed 'none' driver to 'Builtin'. @@ -53,6 +54,7 @@ + @@ -102,6 +104,7 @@ +