/usr/share/php/Horde/Stream/Wrapper/String.php is in php-horde-stream-wrapper 2.1.3-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | <?php
/**
* Copyright 2007-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (BSD). If you
* did not receive this file, see http://www.horde.org/licenses/bsd.
*
* @category Horde
* @copyright 2007-2016 Horde LLC
* @license http://www.horde.org/licenses/bsd BSD
* @package Stream_Wrapper
*/
/**
* A stream wrapper that will treat a native PHP string as a stream.
*
* @author Chuck Hagenbuch <chuck@horde.org>
* @author Michael Slusarz <slusarz@horde.org>
* @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;
}
}
|