Skip to content

Commit

Permalink
[mms] Add Horde_Vfs driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Jul 25, 2014
1 parent ed273db commit be653ab
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 8 deletions.
134 changes: 134 additions & 0 deletions framework/HashTable/lib/Horde/HashTable/Vfs.php
@@ -0,0 +1,134 @@
<?php
/**
* Copyright 2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package HashTable
*/

/**
* Implementation of HashTable for a VFS backend.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package HashTable
* @since 1.2.0
*/
class Horde_HashTable_Vfs
extends Horde_HashTable_Base
{
/* The virtual path to use for VFS data (temporary storage). */
const VFS_PATH = '.horde/core/psession_data';

/**
*/
protected $_persistent = true;

/**
* The VFS object.
*
* @var Horde_Vfs_Base
*/
protected $_vfs;

/**
* @param array $params Additional configuration parameters:
* <pre>
* - vfs: (Horde_Vfs_Base) [REQUIRED] VFS object.
* - vfspath: (string) VFS path to use.
* </pre>
*/
public function __construct(array $params = array())
{
if (!isset($params['vfs'])) {
throw new InvalidArgumentException('Missing vfs parameter.');
}

parent::__construct(array_merge(array(
'vfspath' => 'hashtable_vfs'
), $params));
}

/**
*/
protected function _init()
{
$this->_vfs = $this->_params['vfs'];
}

/**
*/
protected function _delete($keys)
{
$ret = true;

foreach ($keys as $key) {
try {
$this->_vfs->deleteFile($this->_params['vfspath'], $key);
} catch (Horde_Vfs_Exception $e) {
$ret = false;
}
}

return $ret;
}

/**
*/
protected function _exists($keys)
{
$out = array();

foreach ($keys as $key) {
$out[$key] = $this->_vfs->exists($this->_params['vfspath'], $key);
}
return $out;
}

/**
*/
protected function _get($keys)
{
$out = array();

foreach ($keys as $key) {
try {
$out[$key] = $this->_vfs->read($this->_params['vfspath'], $key);
} catch (Horde_Vfs_Exception $e) {
$out[$key] = false;
}
}

return $out;
}

/**
*/
protected function _set($key, $val, $opts)
{
try {
$this->_vfs->writeData($this->_params['vfspath'], $key, $val, true);
} catch (Horde_Vfs_Exception $e) {
return false;
}

return true;
}

/**
*/
public function clear()
{
try {
$this->_vfs->emptyFolder($this->_params['vfspath']);
} catch (Horde_Vfs_Exception $e) {}
}

}
25 changes: 17 additions & 8 deletions framework/HashTable/package.xml
Expand Up @@ -10,18 +10,18 @@
<email>slusarz@horde.org</email>
<active>yes</active>
</lead>
<date>2014-06-04</date>
<date>2014-07-25</date>
<version>
<release>1.1.4</release>
<api>1.1.0</api>
<release>1.2.0</release>
<api>1.2.0</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [mms] Add Horde_Vfs driver.
</notes>
<contents>
<dir baseinstalldir="/" name="/">
Expand All @@ -42,6 +42,7 @@
<file name="Memory.php" role="php" />
<file name="Null.php" role="php" />
<file name="Predis.php" role="php" />
<file name="Vfs.php" role="php" />
</dir> <!-- /lib/Horde/HashTable -->
</dir> <!-- //lib/Horde -->
</dir> <!-- //lib -->
Expand Down Expand Up @@ -93,6 +94,13 @@
<max>3.0.0alpha1</max>
<exclude>3.0.0alpha1</exclude>
</package>
<package>
<name>Horde_Vfs</name>
<channel>pear.horde.org</channel>
<min>2.0.0</min>
<max>3.0.0alpha1</max>
<exclude>3.0.0alpha1</exclude>
</package>
<package>
<name>Predis</name>
<channel>pear.nrk.io</channel>
Expand All @@ -110,6 +118,7 @@
<install as="Horde/HashTable/Memory.php" name="lib/Horde/HashTable/Memory.php" />
<install as="Horde/HashTable/Null.php" name="lib/Horde/HashTable/Null.php" />
<install as="Horde/HashTable/Predis.php" name="lib/Horde/HashTable/Predis.php" />
<install as="Horde/HashTable/Vfs.php" name="lib/Horde/HashTable/Vfs.php" />
<install as="Horde/HashTable/AllTests.php" name="test/Horde/HashTable/AllTests.php" />
<install as="Horde/HashTable/bootstrap.php" name="test/Horde/HashTable/bootstrap.php" />
<install as="Horde/HashTable/phpunit.xml" name="test/Horde/HashTable/phpunit.xml" />
Expand Down Expand Up @@ -242,15 +251,15 @@
</release>
<release>
<version>
<release>1.1.4</release>
<api>1.1.0</api></version>
<release>1.2.0</release>
<api>1.2.0</api></version>
<stability>
<release>stable</release>
<api>stable</api></stability>
<date>2014-06-04</date>
<date>2014-07-25</date>
<license uri="http://www.horde.org/licenses/lgpl21">LGPL-2.1</license>
<notes>
*
* [mms] Add Horde_Vfs driver.
</notes>
</release>
</changelog>
Expand Down

0 comments on commit be653ab

Please sign in to comment.