85 throw new \InvalidArgumentException(
'Stream must be a valid resource but "' . gettype(
$stream) .
'" was given.');
89 $this->customMetadata =
$options->getMetadata();
92 $this->customMetadata = [];
97 $meta = stream_get_meta_data($this->stream);
98 $mode = $meta[
'mode'];
100 $this->readable = array_key_exists($mode, self::$accessMap) && boolval(self::$accessMap[$mode] & self::MASK_ACCESS_READ);
101 $this->writeable = array_key_exists($mode, self::$accessMap) && boolval(self::$accessMap[$mode] & self::MASK_ACCESS_WRITE);
102 $this->seekable = boolval($meta[
'seekable']);
112 if ($this->stream !==
null && is_resource($this->stream)) {
126 $this->stream = $this->size = $this->uri =
null;
139 if ($this->size !==
null) {
144 if ($this->stream ===
null) {
149 if ($this->uri !==
null) {
150 clearstatcache(
true, $this->uri);
153 $stats = fstat($this->stream);
154 if (array_key_exists(
'size',
$stats)) {
155 $this->size =
$stats[
'size'];
174 throw new \RuntimeException(
'Unable to determine stream position');
188 return feof($this->stream);
204 public function seek($offset, $whence = SEEK_SET)
209 throw new \RuntimeException(
'Stream is not seekable');
213 throw new \RuntimeException(
"Unable to seek to stream position \"$offset\" with whence \"$whence\"");
244 throw new \RuntimeException(
'Can not write to a non-writable stream');
252 throw new \RuntimeException(
'Unable to write to stream');
276 throw new \RuntimeException(
'Can not read from non-readable stream');
280 throw new \RuntimeException(
'Length parameter must not be negative');
288 if ($junk ===
false) {
289 throw new \RuntimeException(
'Unable to read from stream');
305 if ($content ===
false) {
306 throw new \RuntimeException(
'Unable to read stream contents');
320 if ($this->stream ===
null) {
326 return array_merge(stream_get_meta_data($this->stream), $this->customMetadata);
332 if (array_key_exists(
$key, $this->customMetadata)) {
333 return $this->customMetadata[
$key];
337 $meta = stream_get_meta_data($this->stream);
338 if (array_key_exists(
$key, $meta)) {
354 }
catch (\Exception $ex) {
368 if (!is_null($this->stream)) {
382 if ($this->stream ===
null) {
383 throw new \RuntimeException(
'Stream is detached');
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
An exception for terminatinating execution or to throw for unit testing.
getMetadata($key=null)
@inheritDoc
__construct($stream, StreamOptions $options=null)
Stream constructor.
const MASK_ACCESS_READ_WRITE
assertStreamAttached()
Checks if the stream is attached to the wrapper.
write($string)
@inheritDoc
seek($offset, $whence=SEEK_SET)
@inheritDoc
static fwrite($handle, $string, $length=null)
fwrite wrapper
static fread($handle, $length)
fread wrapper
static stream_get_contents($handle, $length=-1)
stream_get_contents wrapper
static ftell($handle)
ftell wrapper
static fclose($handle)
fclose wrapper
static fseek($stream, $offset, $whence)
fseek wrapper.