17 use Psr\Http\Message\StreamInterface;
53 $this->resource = fopen(
$stream, $mode);
55 throw new \InvalidArgumentException(
'Invalid stream provided; must be a string stream identifier or resource', 1436717284);
81 }
catch (\RuntimeException $e) {
91 if (!$this->resource) {
108 $this->resource =
null;
119 if ($this->resource ===
null) {
122 $stats = fstat($this->resource);
123 return $stats[
'size'];
132 public function tell()
134 if (!$this->resource) {
135 throw new \RuntimeException(
'No resource available; cannot tell position', 1436717285);
137 $result = ftell($this->resource);
138 if (!is_int($result)) {
139 throw new \RuntimeException(
'Error occurred during tell operation', 1436717286);
149 public function eof()
151 if (!$this->resource) {
154 return feof($this->resource);
164 if (!$this->resource) {
184 public function seek($offset, $whence = SEEK_SET)
186 if (!$this->resource) {
187 throw new \RuntimeException(
'No resource available; cannot seek position', 1436717287);
191 throw new \RuntimeException(
'Stream is not seekable', 1436717288);
193 $result = fseek($this->resource, $offset, $whence);
195 throw new \RuntimeException(
'Error seeking within stream', 1436717289);
221 if (!$this->resource) {
225 return is_writable($uri);
235 public function write($string)
237 if (!$this->resource) {
238 throw new \RuntimeException(
'No resource available; cannot write', 1436717290);
240 $result = fwrite($this->resource, $string);
241 if ($result ===
false) {
242 throw new \RuntimeException(
'Error writing to stream', 1436717291);
254 if (!$this->resource) {
258 return strpos($mode,
'r') !==
false || strpos($mode,
'+') !==
false;
271 public function read($length)
273 if (!$this->resource) {
274 throw new \RuntimeException(
'No resource available; cannot read', 1436717292);
277 throw new \RuntimeException(
'Stream is not readable', 1436717293);
279 $result = fread($this->resource, $length);
280 if ($result ===
false) {
281 throw new \RuntimeException(
'Error reading stream', 1436717294);
298 $result = stream_get_contents($this->resource);
299 if ($result ===
false) {
300 throw new \RuntimeException(
'Error reading from stream', 1436717295);
321 $metadata = stream_get_meta_data($this->resource);
325 if (!isset($metadata[$key])) {
328 return $metadata[$key];
343 set_error_handler(
function ($e) use (&$error) {
347 restore_error_handler();
350 throw new \InvalidArgumentException(
'Invalid stream reference provided', 1436717296);
353 throw new \InvalidArgumentException(
'Invalid stream provided; must be a string stream identifier or resource', 1436717297);