package.xml 0000664 0001750 0001750 00000021253 12654074021 011303 0 ustar jan jan
Horde_Stream_Wrapper
pear.horde.org
Horde Stream wrappers
A collection of stream wrappers.
Chuck Hagenbuch
chuck
chuck@horde.org
yes
Michael Slusarz
slusarz
slusarz@horde.org
yes
2016-02-02
2.1.3
2.1.0
stable
stable
BSD-2-Clause
* [jan] Mark PHP 7 as supported.
5.3.0
8.0.0alpha1
8.0.0alpha1
1.7.0
1.0.0alpha1
1.0.0
alpha
alpha
2011-03-08
BSD-2-Clause
* First alpha release for Horde 4.
1.0.0beta1
1.0.0
beta
beta
2011-03-16
BSD-2-Clause
* First beta release for Horde 4.
1.0.0RC1
1.0.0
beta
beta
2011-03-22
BSD-2-Clause
* First release candidate for Horde 4.
1.0.0RC2
1.0.0
beta
beta
2011-03-29
BSD-2-Clause
* Second release candidate for Horde 4.
1.0.0
1.0.0
stable
stable
2011-04-06
BSD-2-Clause
* First stable release for Horde 4.
1.0.1
1.0.0
stable
stable
2012-04-10
BSD-2-Clause
* [rla] Add license file.
2.0.0alpha1
1.0.0
alpha
stable
2012-07-06
BSD-2-Clause
* First alpha release for Horde 5.
2.0.0beta1
1.0.0
beta
stable
2012-07-19
BSD-2-Clause
* First beta release for Horde 5.
2.0.0
1.0.0
stable
stable
2012-10-30
BSD-2-Clause
* First stable release for Horde 5.
2.0.1
1.0.0
stable
stable
2012-11-22
BSD-2-Clause
* [jan] Re-packaged 2.0.0 release.
2.1.0
2.1.0
stable
stable
2014-02-11
BSD-2-Clause
* [mms] Add unit tests.
* [mms] Add Horde_Stream_Wrapper_Combine::getStream().
* [mms] Add Horde_Stream_Wrapper_String::getStream().
* [mms] Fix documentation regarding proper license for this package (BSD).
2.1.1
2.1.0
stable
stable
2015-01-09
BSD-2-Clause
* [jan] Improve PSR-2 compatibility.
2.1.2
2.1.0
stable
stable
2015-02-10
BSD-2-Clause
* [mms] Fix possible infinite loop when reading from a combined stream.
2.1.3
2.1.0
stable
stable
2016-02-02
BSD-2-Clause
* [jan] Mark PHP 7 as supported.
Horde_Stream_Wrapper-2.1.3/doc/Horde/Stream/Wrapper/COPYING 0000664 0001750 0001750 00000002430 12654074021 021411 0 ustar jan jan Copyright 1999-2016 Horde LLC. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE HORDE PROJECT
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Horde_Stream_Wrapper-2.1.3/lib/Horde/Stream/Wrapper/Combine.php 0000664 0001750 0001750 00000016063 12654074021 022453 0 ustar jan jan
* @category Horde
* @copyright 2009-2016 Horde LLC
* @license http://www.horde.org/licenses/bsd BSD
* @package Stream_Wrapper
*/
class Horde_Stream_Wrapper_Combine
{
/**/
const WRAPPER_NAME = 'horde-stream-wrapper-combine';
/**
* Context.
*
* @var resource
*/
public $context;
/**
* Array that holds the various streams.
*
* @var array
*/
protected $_data = array();
/**
* The combined length of the stream.
*
* @var integer
*/
protected $_length = 0;
/**
* The current position in the string.
*
* @var integer
*/
protected $_position = 0;
/**
* The current position in the data array.
*
* @var integer
*/
protected $_datapos = 0;
/**
* Have we reached EOF?
*
* @var boolean
*/
protected $_ateof = false;
/**
* Unique ID tracker for the streams.
*
* @var integer
*/
private static $_id = 0;
/**
* Create a stream from multiple data sources.
*
* @since 2.1.0
*
* @param array $data An array of strings and/or streams to combine into
* a single stream.
*
* @return resource A PHP stream.
*/
public static function getStream($data)
{
if (!self::$_id) {
stream_wrapper_register(self::WRAPPER_NAME, __CLASS__);
}
return fopen(
self::WRAPPER_NAME . '://' . ++self::$_id,
'wb',
false,
stream_context_create(array(
self::WRAPPER_NAME => array(
'data' => $data
)
))
);
}
/**
* @see streamWrapper::stream_open()
*
* @param string $path
* @param string $mode
* @param integer $options
* @param string &$opened_path
*
* @throws Exception
*/
public function stream_open($path, $mode, $options, &$opened_path)
{
$opts = stream_context_get_options($this->context);
if (isset($opts[self::WRAPPER_NAME]['data'])) {
$data = $opts[self::WRAPPER_NAME]['data'];
} elseif (isset($opts['horde-combine']['data'])) {
// @deprecated
$data = $opts['horde-combine']['data']->getData();
} else {
throw new Exception('Use ' . __CLASS__ . '::getStream() to initialize the stream.');
}
reset($data);
while (list(,$val) = each($data)) {
if (is_string($val)) {
$fp = fopen('php://temp', 'r+');
fwrite($fp, $val);
} else {
$fp = $val;
}
fseek($fp, 0, SEEK_END);
$length = ftell($fp);
rewind($fp);
$this->_data[] = array(
'fp' => $fp,
'l' => $length,
'p' => 0
);
$this->_length += $length;
}
return true;
}
/**
* @see streamWrapper::stream_read()
*
* @param integer $count
*
* @return mixed
*/
public function stream_read($count)
{
if ($this->stream_eof()) {
return false;
}
$out = '';
$tmp = &$this->_data[$this->_datapos];
while ($count) {
if (!is_resource($tmp['fp'])) {
return false;
}
$curr_read = min($count, $tmp['l'] - $tmp['p']);
$out .= fread($tmp['fp'], $curr_read);
$count -= $curr_read;
$this->_position += $curr_read;
if ($this->_position == $this->_length) {
if ($count) {
$this->_ateof = true;
break;
} else {
$tmp['p'] += $curr_read;
}
} elseif ($count) {
if (!isset($this->_data[++$this->_datapos])) {
return false;
}
$tmp = &$this->_data[$this->_datapos];
rewind($tmp['fp']);
$tmp['p'] = 0;
} else {
$tmp['p'] += $curr_read;
}
}
return $out;
}
/**
* @see streamWrapper::stream_write()
*
* @param string $data
*
* @return integer
*/
public function stream_write($data)
{
$tmp = &$this->_data[$this->_datapos];
$oldlen = $tmp['l'];
$res = fwrite($tmp['fp'], $data);
if ($res === false) {
return false;
}
$tmp['p'] = ftell($tmp['fp']);
if ($tmp['p'] > $oldlen) {
$tmp['l'] = $tmp['p'];
$this->_length += ($tmp['l'] - $oldlen);
}
return $res;
}
/**
* @see streamWrapper::stream_tell()
*
* @return integer
*/
public function stream_tell()
{
return $this->_position;
}
/**
* @see streamWrapper::stream_eof()
*
* @return boolean
*/
public function stream_eof()
{
return $this->_ateof;
}
/**
* @see streamWrapper::stream_stat()
*
* @return array
*/
public function stream_stat()
{
return array(
'dev' => 0,
'ino' => 0,
'mode' => 0,
'nlink' => 0,
'uid' => 0,
'gid' => 0,
'rdev' => 0,
'size' => $this->_length,
'atime' => 0,
'mtime' => 0,
'ctime' => 0,
'blksize' => 0,
'blocks' => 0
);
}
/**
* @see streamWrapper::stream_seek()
*
* @param integer $offset
* @param integer $whence SEEK_SET, SEEK_CUR, or SEEK_END
*
* @return boolean
*/
public function stream_seek($offset, $whence)
{
$oldpos = $this->_position;
$this->_ateof = false;
switch ($whence) {
case SEEK_SET:
$offset = $offset;
break;
case SEEK_CUR:
$offset = $this->_position + $offset;
break;
case SEEK_END:
$offset = $this->_length + $offset;
break;
default:
return false;
}
$count = $this->_position = min($this->_length, $offset);
foreach ($this->_data as $key => $val) {
if ($count < $val['l']) {
$this->_datapos = $key;
$val['p'] = $count;
fseek($val['fp'], $count, SEEK_SET);
break;
}
$count -= $val['l'];
}
return ($oldpos != $this->_position);
}
}
Horde_Stream_Wrapper-2.1.3/lib/Horde/Stream/Wrapper/CombineStream.php 0000664 0001750 0001750 00000001503 12654074021 023620 0 ustar jan jan
* @category Horde
* @deprecated Use Horde_Stream_Wrapper_Combine::getStream()
* @copyright 2009-2016 Horde LLC
* @license http://www.horde.org/licenses/bsd BSD
* @package Stream_Wrapper
*/
interface Horde_Stream_Wrapper_CombineStream
{
/**
* Return a reference to the data.
*
* @return array
*/
public function getData();
}
Horde_Stream_Wrapper-2.1.3/lib/Horde/Stream/Wrapper/String.php 0000664 0001750 0001750 00000011061 12654074021 022336 0 ustar jan jan
* @author Michael Slusarz
* @category Horde
* @copyright 2007-2016 Horde LLC
* @license http://www.horde.org/licenses/bsd BSD
* @package Stream_Wrapper
*/
class Horde_Stream_Wrapper_String
{
/**/
const WRAPPER_NAME = 'horde-stream-wrapper-string';
/**
* The current context.
*
* @var resource
*/
public $context;
/**
* String position.
*
* @var integer
*/
protected $_pos;
/**
* The string.
*
* @var string
*/
protected $_string;
/**
* Unique ID tracker for the streams.
*
* @var integer
*/
private static $_id = 0;
/**
* Create a stream from a PHP string.
*
* @since 2.1.0
*
* @param string &$string A PHP string variable.
*
* @return resource A PHP stream pointing to the variable.
*/
public static function getStream(&$string)
{
if (!self::$_id) {
stream_wrapper_register(self::WRAPPER_NAME, __CLASS__);
}
/* Needed to keep reference. */
$ob = new stdClass;
$ob->string = &$string;
return fopen(
self::WRAPPER_NAME . '://' . ++self::$_id,
'wb',
false,
stream_context_create(array(
self::WRAPPER_NAME => array(
'string' => $ob
)
))
);
}
/**
* @see streamWrapper::stream_open()
*/
public function stream_open($path, $mode, $options, &$opened_path)
{
$opts = stream_context_get_options($this->context);
if (isset($opts[self::WRAPPER_NAME]['string'])) {
$this->_string =& $opts[self::WRAPPER_NAME]['string']->string;
} elseif (isset($opts['horde-string']['string'])) {
// @deprecated
$this->_string =& $opts['horde-string']['string']->getString();
} else {
throw new Exception('Use ' . __CLASS__ . '::getStream() to initialize the stream.');
}
if (is_null($this->_string)) {
return false;
}
$this->_pos = 0;
return true;
}
/**
* @see streamWrapper::stream_close()
*/
public function stream_close()
{
$this->_string = '';
$this->_pos = 0;
}
/**
* @see streamWrapper::stream_read()
*/
public function stream_read($count)
{
$curr = $this->_pos;
$this->_pos += $count;
return substr($this->_string, $curr, $count);
}
/**
* @see streamWrapper::stream_write()
*/
public function stream_write($data)
{
$len = strlen($data);
$this->_string = substr_replace($this->_string, $data, $this->_pos, $len);
$this->_pos += $len;
return $len;
}
/**
* @see streamWrapper::stream_tell()
*/
public function stream_tell()
{
return $this->_pos;
}
/**
* @see streamWrapper::stream_eof()
*/
public function stream_eof()
{
return ($this->_pos > strlen($this->_string));
}
/**
* @see streamWrapper::stream_stat()
*/
public function stream_stat()
{
return array(
'dev' => 0,
'ino' => 0,
'mode' => 0,
'nlink' => 0,
'uid' => 0,
'gid' => 0,
'rdev' => 0,
'size' => strlen($this->_string),
'atime' => 0,
'mtime' => 0,
'ctime' => 0,
'blksize' => 0,
'blocks' => 0
);
}
/**
* @see streamWrapper::stream_seek()
*/
public function stream_seek($offset, $whence)
{
switch ($whence) {
case SEEK_SET:
$pos = $offset;
break;
case SEEK_CUR:
$pos = $this->_pos + $offset;
break;
case SEEK_END:
$pos = strlen($this->_string) + $offset;
break;
}
if (($pos < 0) || ($pos > strlen($this->_string))) {
return false;
}
$this->_pos = $pos;
return true;
}
}
Horde_Stream_Wrapper-2.1.3/lib/Horde/Stream/Wrapper/StringStream.php 0000664 0001750 0001750 00000001513 12654074021 023513 0 ustar jan jan
* @category Horde
* @copyright 2007-2016 Horde LLC
* @deprecated Use Horde_Stream_Wrapper_String::getStream()
* @license http://www.horde.org/licenses/bsd BSD
* @package Stream_Wrapper
*/
interface Horde_Stream_Wrapper_StringStream
{
/**
* Return a reference to the wrapped string.
*
* @return string
*/
public function &getString();
}
Horde_Stream_Wrapper-2.1.3/test/Horde/Stream/Wrapper/AllTests.php 0000664 0001750 0001750 00000000132 12654074021 023031 0 ustar jan jan run();
Horde_Stream_Wrapper-2.1.3/test/Horde/Stream/Wrapper/bootstrap.php 0000664 0001750 0001750 00000000143 12654074021 023315 0 ustar jan jan
* @category Horde
* @copyright 2009-2016 Horde LLC
* @ignore
* @license http://www.horde.org/licenses/bsd BSD
* @package Stream_Wrapper
* @subpackage UnitTests
*/
class Horde_Stream_Wrapper_CombineTest extends PHPUnit_Framework_TestCase
{
public function testUsage()
{
$fp = fopen('php://temp', 'r+');
fwrite($fp, '12345');
$data = array('ABCDE', $fp, 'fghij');
$stream = Horde_Stream_Wrapper_Combine::getStream($data);
$this->assertEquals('ABCDE12345fghij', fread($stream, 1024));
$this->assertEquals(true, feof($stream));
$this->assertEquals(0, fseek($stream, 0));
$this->assertEquals(-1, fseek($stream, 0));
$this->assertEquals(0, ftell($stream));
$this->assertEquals(0, fseek($stream, 5, SEEK_CUR));
$this->assertEquals(5, ftell($stream));
$this->assertEquals(10, fwrite($stream, '0000000000'));
$this->assertEquals(0, fseek($stream, 0, SEEK_END));
$this->assertEquals(20, ftell($stream));
$this->assertEquals(false, feof($stream));
fclose($stream);
}
}
Horde_Stream_Wrapper-2.1.3/test/Horde/Stream/Wrapper/phpunit.xml 0000664 0001750 0001750 00000000056 12654074021 023003 0 ustar jan jan
Horde_Stream_Wrapper-2.1.3/test/Horde/Stream/Wrapper/StringTest.php 0000664 0001750 0001750 00000004001 12654074021 023403 0 ustar jan jan
* @category Horde
* @copyright 2008-2016 Horde LLC
* @ignore
* @license http://www.horde.org/licenses/bsd BSD
* @package Stream_Wrapper
* @subpackage UnitTests
*/
class Horde_Stream_Wrapper_StringTest extends PHPUnit_Framework_TestCase
{
public function testUsage()
{
$string = 'ABCDE12345fghij';
$stream = Horde_Stream_Wrapper_String::getStream($string);
$this->assertEquals('ABCDE12345fghij', fread($stream, 1024));
$this->assertEquals(true, feof($stream));
$this->assertEquals(0, fseek($stream, 0));
$this->assertEquals(0, fseek($stream, 0));
$this->assertEquals(0, ftell($stream));
$this->assertEquals(0, fseek($stream, 5, SEEK_CUR));
$this->assertEquals(5, ftell($stream));
$this->assertEquals(10, fwrite($stream, '0000000000'));
$this->assertEquals(0, fseek($stream, 0, SEEK_END));
$this->assertEquals(15, ftell($stream));
$this->assertEquals(false, feof($stream));
fclose($stream);
}
public function testMemoryUsage()
{
$bytes = 1024 * 1024;
$string = str_repeat('*', $bytes);
$memoryUsage = memory_get_usage();
$stream = Horde_Stream_Wrapper_String::getStream($string);
$memoryUsage2 = memory_get_usage();
$this->assertLessThan($memoryUsage + $bytes, $memoryUsage2);
while (!feof($stream)) {
fread($stream, 1024);
}
$memoryUsage3 = memory_get_usage();
$this->assertLessThan($memoryUsage + $bytes, $memoryUsage3);
}
}