[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\Filesystem\Streams; 11 12 \defined('JPATH_PLATFORM') or die; 13 14 use Joomla\CMS\Filesystem\Support\StringController; 15 16 /** 17 * String Stream Wrapper 18 * 19 * This class allows you to use a PHP string in the same way that 20 * you would normally use a regular stream wrapper 21 * 22 * @since 1.7.0 23 */ 24 class StreamString 25 { 26 /** 27 * The current string 28 * 29 * @var string 30 * @since 3.0.0 31 */ 32 protected $currentString; 33 34 /** 35 * The path 36 * 37 * @var string 38 * @since 3.0.0 39 */ 40 protected $path; 41 42 /** 43 * The mode 44 * 45 * @var string 46 * @since 3.0.0 47 */ 48 protected $mode; 49 50 /** 51 * Enter description here ... 52 * 53 * @var string 54 * @since 3.0.0 55 */ 56 protected $options; 57 58 /** 59 * Enter description here ... 60 * 61 * @var string 62 * @since 3.0.0 63 */ 64 protected $openedPath; 65 66 /** 67 * Current position 68 * 69 * @var integer 70 * @since 3.0.0 71 */ 72 protected $pos; 73 74 /** 75 * Length of the string 76 * 77 * @var string 78 * @since 3.0.0 79 */ 80 protected $len; 81 82 /** 83 * Statistics for a file 84 * 85 * @var array 86 * @since 3.0.0 87 * 88 * @link http://us.php.net/manual/en/function.stat.php 89 */ 90 protected $stat; 91 92 /** 93 * Method to open a file or URL. 94 * 95 * @param string $path The stream path. 96 * @param string $mode Not used. 97 * @param integer $options Not used. 98 * @param string $openedPath Not used. 99 * 100 * @return boolean 101 * 102 * @since 1.7.0 103 */ 104 public function stream_open($path, $mode, $options, &$openedPath) 105 { 106 $this->currentString = &StringController::getRef(str_replace('string://', '', $path)); 107 108 if ($this->currentString) { 109 $this->len = \strlen($this->currentString); 110 $this->pos = 0; 111 $this->stat = $this->url_stat($path, 0); 112 113 return true; 114 } else { 115 return false; 116 } 117 } 118 119 /** 120 * Method to retrieve information from a file resource 121 * 122 * @return array 123 * 124 * @link https://www.php.net/manual/en/streamwrapper.stream-stat.php 125 * @since 1.7.0 126 */ 127 public function stream_stat() 128 { 129 return $this->stat; 130 } 131 132 /** 133 * Method to retrieve information about a file. 134 * 135 * @param string $path File path or URL to stat 136 * @param integer $flags Additional flags set by the streams API 137 * 138 * @return array 139 * 140 * @link https://www.php.net/manual/en/streamwrapper.url-stat.php 141 * @since 1.7.0 142 */ 143 public function url_stat($path, $flags = 0) 144 { 145 $now = time(); 146 $string = &StringController::getRef(str_replace('string://', '', $path)); 147 $stat = array( 148 'dev' => 0, 149 'ino' => 0, 150 'mode' => 0, 151 'nlink' => 1, 152 'uid' => 0, 153 'gid' => 0, 154 'rdev' => 0, 155 'size' => \strlen($string), 156 'atime' => $now, 157 'mtime' => $now, 158 'ctime' => $now, 159 'blksize' => '512', 160 'blocks' => ceil(\strlen($string) / 512), 161 ); 162 163 return $stat; 164 } 165 166 /** 167 * Method to read a given number of bytes starting at the current position 168 * and moving to the end of the string defined by the current position plus the 169 * given number. 170 * 171 * @param integer $count Bytes of data from the current position should be returned. 172 * 173 * @return string 174 * 175 * @since 1.7.0 176 * 177 * @link https://www.php.net/manual/en/streamwrapper.stream-read.php 178 */ 179 public function stream_read($count) 180 { 181 $result = substr($this->currentString, $this->pos, $count); 182 $this->pos += $count; 183 184 return $result; 185 } 186 187 /** 188 * Stream write, always returning false. 189 * 190 * @param string $data The data to write. 191 * 192 * @return boolean 193 * 194 * @since 1.7.0 195 * @note Updating the string is not supported. 196 */ 197 public function stream_write($data) 198 { 199 // We don't support updating the string. 200 return false; 201 } 202 203 /** 204 * Method to get the current position 205 * 206 * @return integer The position 207 * 208 * @since 1.7.0 209 */ 210 public function stream_tell() 211 { 212 return $this->pos; 213 } 214 215 /** 216 * End of field check 217 * 218 * @return boolean True if at end of field. 219 * 220 * @since 1.7.0 221 */ 222 public function stream_eof() 223 { 224 if ($this->pos > $this->len) { 225 return true; 226 } 227 228 return false; 229 } 230 231 /** 232 * Stream offset 233 * 234 * @param integer $offset The starting offset. 235 * @param integer $whence SEEK_SET, SEEK_CUR, SEEK_END 236 * 237 * @return boolean True on success. 238 * 239 * @since 1.7.0 240 */ 241 public function stream_seek($offset, $whence) 242 { 243 // $whence: SEEK_SET, SEEK_CUR, SEEK_END 244 if ($offset > $this->len) { 245 // We can't seek beyond our len. 246 return false; 247 } 248 249 switch ($whence) { 250 case SEEK_SET: 251 $this->pos = $offset; 252 break; 253 254 case SEEK_CUR: 255 if (($this->pos + $offset) < $this->len) { 256 $this->pos += $offset; 257 } else { 258 return false; 259 } 260 break; 261 262 case SEEK_END: 263 $this->pos = $this->len - $offset; 264 break; 265 } 266 267 return true; 268 } 269 270 /** 271 * Stream flush, always returns true. 272 * 273 * @return boolean 274 * 275 * @since 1.7.0 276 * @note Data storage is not supported 277 */ 278 public function stream_flush() 279 { 280 // We don't store data. 281 return true; 282 } 283 } 284 285 stream_wrapper_register('string', '\\Joomla\\CMS\\Filesystem\\Streams\\StreamString') or die('StreamString Wrapper Registration Failed');
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |