2 declare(strict_types=1);
25 'r' => self::MASK_ACCESS_READ,
26 'w+' => self::MASK_ACCESS_READ_WRITE,
27 'r+' => self::MASK_ACCESS_READ_WRITE,
28 'x+' => self::MASK_ACCESS_READ_WRITE,
29 'c+' => self::MASK_ACCESS_READ_WRITE,
30 'rb' => self::MASK_ACCESS_READ,
31 'w+b' => self::MASK_ACCESS_READ_WRITE,
32 'r+b' => self::MASK_ACCESS_READ_WRITE,
33 'x+b' => self::MASK_ACCESS_READ_WRITE,
34 'c+b' => self::MASK_ACCESS_READ_WRITE,
35 'rt' => self::MASK_ACCESS_READ,
36 'w+t' => self::MASK_ACCESS_READ_WRITE,
37 'r+t' => self::MASK_ACCESS_READ_WRITE,
38 'x+t' => self::MASK_ACCESS_READ_WRITE,
39 'c+t' => self::MASK_ACCESS_READ_WRITE,
40 'a+' => self::MASK_ACCESS_READ_WRITE,
41 'w' => self::MASK_ACCESS_WRITE,
42 'rw' => self::MASK_ACCESS_WRITE,
43 'wb' => self::MASK_ACCESS_WRITE,
44 'a' => self::MASK_ACCESS_WRITE
86 throw new \InvalidArgumentException(
'Stream must be a valid resource but "' . gettype(
$stream) .
'" was given.');
90 $this->customMetadata =
$options->getMetadata();
93 $this->customMetadata = [];
98 $meta = stream_get_meta_data($this->stream);
99 $mode = $meta[
'mode'];
101 $this->readable = array_key_exists($mode, self::$accessMap) && boolval(self::$accessMap[$mode] & self::MASK_ACCESS_READ);
102 $this->writeable = array_key_exists($mode, self::$accessMap) && boolval(self::$accessMap[$mode] & self::MASK_ACCESS_WRITE);
103 $this->seekable = boolval($meta[
'seekable']);
113 if ($this->stream !== null && is_resource($this->stream)) {
127 $this->stream = $this->
size = $this->uri = null;
140 if ($this->
size !== null) {
145 if ($this->stream === null) {
150 if ($this->uri !== null) {
151 clearstatcache(
true, $this->uri);
154 $stats = fstat($this->stream);
155 if (array_key_exists(
'size',
$stats)) {
175 throw new \RuntimeException(
'Unable to determine stream position');
189 return feof($this->stream);
205 public function seek($offset, $whence = SEEK_SET)
210 throw new \RuntimeException(
'Stream is not seekable');
214 throw new \RuntimeException(
"Unable to seek to stream position \"$offset\" with whence \"$whence\"");
245 throw new \RuntimeException(
'Can not write to a non-writable stream');
253 throw new \RuntimeException(
'Unable to write to stream');
277 throw new \RuntimeException(
'Can not read from non-readable stream');
281 throw new \RuntimeException(
'Length parameter must not be negative');
289 if ($junk ===
false) {
290 throw new \RuntimeException(
'Unable to read from stream');
306 if ($content ===
false) {
307 throw new \RuntimeException(
'Unable to read stream contents');
321 if ($this->stream === null) {
327 return array_merge(stream_get_meta_data($this->stream), $this->customMetadata);
333 if (array_key_exists(
$key, $this->customMetadata)) {
334 return $this->customMetadata[
$key];
338 $meta = stream_get_meta_data($this->stream);
339 if (array_key_exists(
$key, $meta)) {
369 if (!is_null($this->stream)) {
383 if ($this->stream === null) {
384 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