--- /dev/null
+<?php
+/**
+ * SessionHandler implementation for storage in text files.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author Michael Slusarz <slusarz@horde.org>
+ * @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:
+ * <pre>
+ * path - (string) [REQUIRED] The path to save the files.
+ * </pre>
+ *
+ * @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;
+ }
+
+}
<api>beta</api>
</stability>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Abstracted storage-specific code into 'Storage' drivers.
+ <notes>* 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'.
<dir name="Storage">
<file name="Builtin.php" role="php" />
<file name="External.php" role="php" />
+ <file name="File.php" role="php" />
<file name="Memcache.php" role="php" />
<file name="Sql.php" role="php" />
<file name="Stack.php" role="php" />
<install as="Horde/SessionHandler.php" name="lib/Horde/SessionHandler.php" />
<install as="Horde/SessionHandler/Storage/Builtin.php" name="lib/Horde/SessionHandler/Storage/Builtin.php" />
<install as="Horde/SessionHandler/Storage/External.php" name="lib/Horde/SessionHandler/Storage/External.php" />
+ <install as="Horde/SessionHandler/Storage/File.php" name="lib/Horde/SessionHandler/Storage/File.php" />
<install as="Horde/SessionHandler/Storage/Memcache.php" name="lib/Horde/SessionHandler/Storage/Memcache.php" />
<install as="Horde/SessionHandler/Storage/Sql.php" name="lib/Horde/SessionHandler/Storage/Sql.php" />
<install as="Horde/SessionHandler/Storage/Stack.php" name="lib/Horde/SessionHandler/Storage/Stack.php" />