comparison vendor/guzzlehttp/psr7/src/Stream.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
22 private static $readWriteHash = [ 22 private static $readWriteHash = [
23 'read' => [ 23 'read' => [
24 'r' => true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true, 24 'r' => true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true,
25 'rb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true, 25 'rb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true,
26 'c+b' => true, 'rt' => true, 'w+t' => true, 'r+t' => true, 26 'c+b' => true, 'rt' => true, 'w+t' => true, 'r+t' => true,
27 'x+t' => true, 'c+t' => true, 'a+' => true 27 'x+t' => true, 'c+t' => true, 'a+' => true, 'rb+' => true,
28 ], 28 ],
29 'write' => [ 29 'write' => [
30 'w' => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true, 30 'w' => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true,
31 'c+' => true, 'wb' => true, 'w+b' => true, 'r+b' => true, 31 'c+' => true, 'wb' => true, 'w+b' => true, 'r+b' => true, 'rb+' => true,
32 'x+b' => true, 'c+b' => true, 'w+t' => true, 'r+t' => true, 32 'x+b' => true, 'c+b' => true, 'w+t' => true, 'r+t' => true,
33 'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true 33 'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true
34 ] 34 ]
35 ]; 35 ];
36 36
68 $this->readable = isset(self::$readWriteHash['read'][$meta['mode']]); 68 $this->readable = isset(self::$readWriteHash['read'][$meta['mode']]);
69 $this->writable = isset(self::$readWriteHash['write'][$meta['mode']]); 69 $this->writable = isset(self::$readWriteHash['write'][$meta['mode']]);
70 $this->uri = $this->getMetadata('uri'); 70 $this->uri = $this->getMetadata('uri');
71 } 71 }
72 72
73 public function __get($name)
74 {
75 if ($name == 'stream') {
76 throw new \RuntimeException('The stream is detached');
77 }
78
79 throw new \BadMethodCallException('No value for ' . $name);
80 }
81
82 /** 73 /**
83 * Closes the stream when the destructed 74 * Closes the stream when the destructed
84 */ 75 */
85 public function __destruct() 76 public function __destruct()
86 { 77 {
97 } 88 }
98 } 89 }
99 90
100 public function getContents() 91 public function getContents()
101 { 92 {
93 if (!isset($this->stream)) {
94 throw new \RuntimeException('Stream is detached');
95 }
96
102 $contents = stream_get_contents($this->stream); 97 $contents = stream_get_contents($this->stream);
103 98
104 if ($contents === false) { 99 if ($contents === false) {
105 throw new \RuntimeException('Unable to read stream contents'); 100 throw new \RuntimeException('Unable to read stream contents');
106 } 101 }
171 return $this->seekable; 166 return $this->seekable;
172 } 167 }
173 168
174 public function eof() 169 public function eof()
175 { 170 {
176 return !$this->stream || feof($this->stream); 171 if (!isset($this->stream)) {
172 throw new \RuntimeException('Stream is detached');
173 }
174
175 return feof($this->stream);
177 } 176 }
178 177
179 public function tell() 178 public function tell()
180 { 179 {
180 if (!isset($this->stream)) {
181 throw new \RuntimeException('Stream is detached');
182 }
183
181 $result = ftell($this->stream); 184 $result = ftell($this->stream);
182 185
183 if ($result === false) { 186 if ($result === false) {
184 throw new \RuntimeException('Unable to determine stream position'); 187 throw new \RuntimeException('Unable to determine stream position');
185 } 188 }
192 $this->seek(0); 195 $this->seek(0);
193 } 196 }
194 197
195 public function seek($offset, $whence = SEEK_SET) 198 public function seek($offset, $whence = SEEK_SET)
196 { 199 {
200 if (!isset($this->stream)) {
201 throw new \RuntimeException('Stream is detached');
202 }
197 if (!$this->seekable) { 203 if (!$this->seekable) {
198 throw new \RuntimeException('Stream is not seekable'); 204 throw new \RuntimeException('Stream is not seekable');
199 } elseif (fseek($this->stream, $offset, $whence) === -1) { 205 }
206 if (fseek($this->stream, $offset, $whence) === -1) {
200 throw new \RuntimeException('Unable to seek to stream position ' 207 throw new \RuntimeException('Unable to seek to stream position '
201 . $offset . ' with whence ' . var_export($whence, true)); 208 . $offset . ' with whence ' . var_export($whence, true));
202 } 209 }
203 } 210 }
204 211
205 public function read($length) 212 public function read($length)
206 { 213 {
214 if (!isset($this->stream)) {
215 throw new \RuntimeException('Stream is detached');
216 }
207 if (!$this->readable) { 217 if (!$this->readable) {
208 throw new \RuntimeException('Cannot read from non-readable stream'); 218 throw new \RuntimeException('Cannot read from non-readable stream');
209 } 219 }
210 if ($length < 0) { 220 if ($length < 0) {
211 throw new \RuntimeException('Length parameter cannot be negative'); 221 throw new \RuntimeException('Length parameter cannot be negative');
223 return $string; 233 return $string;
224 } 234 }
225 235
226 public function write($string) 236 public function write($string)
227 { 237 {
238 if (!isset($this->stream)) {
239 throw new \RuntimeException('Stream is detached');
240 }
228 if (!$this->writable) { 241 if (!$this->writable) {
229 throw new \RuntimeException('Cannot write to a non-writable stream'); 242 throw new \RuntimeException('Cannot write to a non-writable stream');
230 } 243 }
231 244
232 // We can't know the size after writing anything 245 // We can't know the size after writing anything