[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Part of the Joomla Framework Filesystem Package 4 * 5 * @copyright Copyright (C) 2005 - 2021 Open Source Matters, Inc. All rights reserved. 6 * @license GNU General Public License version 2 or later; see LICENSE 7 */ 8 9 namespace Joomla\Filesystem; 10 11 /** 12 * Generic Buffer stream handler 13 * 14 * This class provides a generic buffer stream. It can be used to store/retrieve/manipulate 15 * string buffers with the standard PHP filesystem I/O methods. 16 * 17 * @since 1.0 18 */ 19 class Buffer 20 { 21 /** 22 * Stream position 23 * 24 * @var integer 25 * @since 1.0 26 */ 27 public $position = 0; 28 29 /** 30 * Buffer name 31 * 32 * @var string 33 * @since 1.0 34 */ 35 public $name; 36 37 /** 38 * Buffer hash 39 * 40 * @var array 41 * @since 1.0 42 */ 43 public $buffers = []; 44 45 /** 46 * Function to open file or url 47 * 48 * @param string $path The URL that was passed 49 * @param string $mode Mode used to open the file @see fopen 50 * @param integer $options Flags used by the API, may be STREAM_USE_PATH and STREAM_REPORT_ERRORS 51 * @param string $openedPath Full path of the resource. Used with STREAN_USE_PATH option 52 * 53 * @return boolean 54 * 55 * @since 1.0 56 * @see streamWrapper::stream_open 57 */ 58 public function stream_open($path, $mode, $options, &$openedPath) 59 { 60 $url = parse_url($path); 61 $this->name = $url['host']; 62 $this->buffers[$this->name] = null; 63 $this->position = 0; 64 65 return true; 66 } 67 68 /** 69 * Read stream 70 * 71 * @param integer $count How many bytes of data from the current position should be returned. 72 * 73 * @return mixed The data from the stream up to the specified number of bytes (all data if 74 * the total number of bytes in the stream is less than $count. Null if 75 * the stream is empty. 76 * 77 * @see streamWrapper::stream_read 78 * @since 1.0 79 */ 80 public function stream_read($count) 81 { 82 $ret = substr($this->buffers[$this->name], $this->position, $count); 83 $this->position += \strlen($ret); 84 85 return $ret; 86 } 87 88 /** 89 * Write stream 90 * 91 * @param string $data The data to write to the stream. 92 * 93 * @return integer 94 * 95 * @see streamWrapper::stream_write 96 * @since 1.0 97 */ 98 public function stream_write($data) 99 { 100 $left = substr($this->buffers[$this->name], 0, $this->position); 101 $right = substr($this->buffers[$this->name], $this->position + \strlen($data)); 102 $this->buffers[$this->name] = $left . $data . $right; 103 $this->position += \strlen($data); 104 105 return \strlen($data); 106 } 107 108 /** 109 * Function to get the current position of the stream 110 * 111 * @return integer 112 * 113 * @see streamWrapper::stream_tell 114 * @since 1.0 115 */ 116 public function stream_tell() 117 { 118 return $this->position; 119 } 120 121 /** 122 * Function to test for end of file pointer 123 * 124 * @return boolean True if the pointer is at the end of the stream 125 * 126 * @see streamWrapper::stream_eof 127 * @since 1.0 128 */ 129 public function stream_eof() 130 { 131 return $this->position >= \strlen($this->buffers[$this->name]); 132 } 133 134 /** 135 * The read write position updates in response to $offset and $whence 136 * 137 * @param integer $offset The offset in bytes 138 * @param integer $whence Position the offset is added to 139 * Options are SEEK_SET, SEEK_CUR, and SEEK_END 140 * 141 * @return boolean True if updated 142 * 143 * @see streamWrapper::stream_seek 144 * @since 1.0 145 */ 146 public function stream_seek($offset, $whence) 147 { 148 switch ($whence) 149 { 150 case \SEEK_SET: 151 if ($offset < \strlen($this->buffers[$this->name]) && $offset >= 0) 152 { 153 $this->position = $offset; 154 155 return true; 156 } 157 158 return false; 159 160 case \SEEK_CUR: 161 if ($offset >= 0) 162 { 163 $this->position += $offset; 164 165 return true; 166 } 167 168 return false; 169 170 case \SEEK_END: 171 if (\strlen($this->buffers[$this->name]) + $offset >= 0) 172 { 173 $this->position = \strlen($this->buffers[$this->name]) + $offset; 174 175 return true; 176 } 177 178 return false; 179 180 default: 181 return false; 182 } 183 } 184 } 185 186 // Register the stream 187 stream_wrapper_register('buffer', 'Joomla\\Filesystem\\Buffer');
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 |