From 6fb5ebed4b51c91b1d3a411b7295edf009803d44 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 25 Jul 2014 01:07:33 -0600 Subject: [PATCH] Add code to VFS hashtable driver to allow stream data to be returned Will allow us to replace current (duplicate) code currently in IMP. --- .../HashTable/lib/Horde/HashTable/Vfs.php | 29 +++++++++++++++++-- framework/HashTable/package.xml | 7 +++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/framework/HashTable/lib/Horde/HashTable/Vfs.php b/framework/HashTable/lib/Horde/HashTable/Vfs.php index b4ac42ac35d..7ad9c2fc46c 100644 --- a/framework/HashTable/lib/Horde/HashTable/Vfs.php +++ b/framework/HashTable/lib/Horde/HashTable/Vfs.php @@ -27,6 +27,13 @@ class Horde_HashTable_Vfs /* The virtual path to use for VFS data (temporary storage). */ const VFS_PATH = '.horde/core/psession_data'; + /** + * If set, return data from get() as Horde_Stream objects, not strings. + * + * @var boolean + */ + public $stream = false; + /** */ protected $_persistent = true; @@ -89,6 +96,7 @@ protected function _exists($keys) foreach ($keys as $key) { $out[$key] = $this->_vfs->exists($this->_params['vfspath'], $key); } + return $out; } @@ -100,10 +108,27 @@ protected function _get($keys) foreach ($keys as $key) { try { - $out[$key] = $this->_vfs->read($this->_params['vfspath'], $key); + if ($this->stream) { + if (method_exists($this->_vfs, 'readStream')) { + $data = new Horde_Stream_Existing(array( + 'stream' => $this->_vfs->readStream($this->_params['vfspath'], $key) + )); + $data->rewind(); + } else { + $data = new Horde_Stream_Temp(); + $data->add( + $this->_vfs->read($this->_params['vfspath'], $key), + true + ); + } + } else { + $data = $this->_vfs->read($this->_params['vfspath'], $key); + } } catch (Horde_Vfs_Exception $e) { - $out[$key] = false; + $data = false; } + + $out[$key] = $data; } return $out; diff --git a/framework/HashTable/package.xml b/framework/HashTable/package.xml index 7b49386b65b..73fdc3d8db7 100644 --- a/framework/HashTable/package.xml +++ b/framework/HashTable/package.xml @@ -94,6 +94,13 @@ 3.0.0alpha1 3.0.0alpha1 + + Horde_Stream + pear.horde.org + 1.2.0 + 2.0.0alpha1 + 2.0.0alpha1 + Horde_Vfs pear.horde.org