| @@ 256-269 (lines=14) @@ | ||
| 253 | * @return int Returns the number of bytes written to the stream. |
|
| 254 | * @throws \RuntimeException on failure. |
|
| 255 | */ |
|
| 256 | public function write($string) |
|
| 257 | { |
|
| 258 | if (! $this->resource) { |
|
| 259 | throw new RuntimeException('No resource available; cannot write'); |
|
| 260 | } |
|
| 261 | if (! $this->isWritable()) { |
|
| 262 | throw new RuntimeException('Stream is not writable'); |
|
| 263 | } |
|
| 264 | $result = fwrite($this->resource, $string); |
|
| 265 | if (false === $result) { |
|
| 266 | throw new RuntimeException('Error writing to stream'); |
|
| 267 | } |
|
| 268 | return $result; |
|
| 269 | } |
|
| 270 | ||
| 271 | /** |
|
| 272 | * Returns whether or not the stream is readable. |
|
| @@ 296-309 (lines=14) @@ | ||
| 293 | * if no bytes are available. |
|
| 294 | * @throws \RuntimeException if an error occurs. |
|
| 295 | */ |
|
| 296 | public function read($length) |
|
| 297 | { |
|
| 298 | if (! $this->resource) { |
|
| 299 | throw new RuntimeException('No resource available; cannot read'); |
|
| 300 | } |
|
| 301 | if (! $this->isReadable()) { |
|
| 302 | throw new RuntimeException('Stream is not readable'); |
|
| 303 | } |
|
| 304 | $result = fread($this->resource, $length); |
|
| 305 | if (false === $result) { |
|
| 306 | throw new RuntimeException('Error reading stream'); |
|
| 307 | } |
|
| 308 | return $result; |
|
| 309 | } |
|
| 310 | ||
| 311 | /** |
|
| 312 | * Returns the remaining contents in a string |
|