2 declare(strict_types=1);
22 'r' => self::MASK_ACCESS_READ,
23 'w+' => self::MASK_ACCESS_READ_WRITE,
24 'r+' => self::MASK_ACCESS_READ_WRITE,
25 'x+' => self::MASK_ACCESS_READ_WRITE,
26 'c+' => self::MASK_ACCESS_READ_WRITE,
27 'rb' => self::MASK_ACCESS_READ,
28 'w+b' => self::MASK_ACCESS_READ_WRITE,
29 'r+b' => self::MASK_ACCESS_READ_WRITE,
30 'x+b' => self::MASK_ACCESS_READ_WRITE,
31 'c+b' => self::MASK_ACCESS_READ_WRITE,
32 'rt' => self::MASK_ACCESS_READ,
33 'w+t' => self::MASK_ACCESS_READ_WRITE,
34 'r+t' => self::MASK_ACCESS_READ_WRITE,
35 'x+t' => self::MASK_ACCESS_READ_WRITE,
36 'c+t' => self::MASK_ACCESS_READ_WRITE,
37 'a+' => self::MASK_ACCESS_READ_WRITE,
38 'w' => self::MASK_ACCESS_WRITE,
39 'rw' => self::MASK_ACCESS_WRITE,
40 'wb' => self::MASK_ACCESS_WRITE,
41 'a' => self::MASK_ACCESS_WRITE
81 throw new \InvalidArgumentException(
'Stream must be a valid resource but "' . gettype(
$stream) .
'" was given.');
84 if ($options !== null) {
85 $this->customMetadata = $options->getMetadata();
86 $this->size = ($options->getSize() !== -1) ? $options->getSize() : null;
88 $this->customMetadata = [];
93 $meta = stream_get_meta_data($this->stream);
94 $mode = $meta[
'mode'];
96 $this->readable = array_key_exists($mode,
97 self::$accessMap) && boolval(self::$accessMap[$mode]&self::MASK_ACCESS_READ);
98 $this->writeable = array_key_exists($mode,
99 self::$accessMap) && boolval(self::$accessMap[$mode]&self::MASK_ACCESS_WRITE);
100 $this->seekable = boolval($meta[
'seekable']);
109 if ($this->stream !== null && is_resource($this->stream)) {
122 $this->stream = $this->size = $this->uri = null;
134 if ($this->size !== null) {
139 if ($this->stream === null) {
144 if ($this->uri !== null) {
145 clearstatcache(
true, $this->uri);
148 $stats = fstat($this->stream);
149 if (array_key_exists(
'size', $stats)) {
150 $this->size = $stats[
'size'];
168 throw new \RuntimeException(
'Unable to determine stream position');
181 return feof($this->stream);
195 public function seek($offset, $whence = SEEK_SET)
200 throw new \RuntimeException(
'Stream is not seekable');
204 throw new \RuntimeException(
"Unable to seek to stream position \"$offset\" with whence \"$whence\"");
232 throw new \RuntimeException(
'Can not write to a non-writable stream');
240 throw new \RuntimeException(
'Unable to write to stream');
262 throw new \RuntimeException(
'Can not read from non-readable stream');
266 throw new \RuntimeException(
'Length parameter must not be negative');
274 if ($junk ===
false) {
275 throw new \RuntimeException(
'Unable to read from stream');
290 if ($content ===
false) {
291 throw new \RuntimeException(
'Unable to read stream contents');
304 if ($this->stream === null) {
310 return array_merge(stream_get_meta_data($this->stream), $this->customMetadata);
316 if (array_key_exists($key, $this->customMetadata)) {
317 return $this->customMetadata[$key];
321 $meta = stream_get_meta_data($this->stream);
322 if (array_key_exists($key, $meta)) {
351 if (!is_null($this->stream)) {
363 if ($this->stream === null) {
364 throw new \RuntimeException(
'Stream is detached');
static ftell($handle)
ftell wrapper
seek($offset, $whence=SEEK_SET)
assertStreamAttached()
Checks if the stream is attached to the wrapper.
static fseek($stream, $offset, $whence)
fseek wrapper.
static fread($handle, $length)
fread wrapper
static fclose($handle)
fclose wrapper
__construct($stream, StreamOptions $options=null)
Stream constructor.
const MASK_ACCESS_READ_WRITE
static fwrite($handle, $string, $length=null)
fwrite wrapper
static stream_get_contents($handle, $length=-1)
stream_get_contents wrapper
Interface FileStream The base interface for all filesystem streams.
Class StreamOptions The streaming options are used by the stream implementation.