18 private static $slots = [
'__toString',
'close',
'detach',
'rewind',
19 'getSize',
'tell',
'eof',
'isSeekable',
'seek',
'isWritable',
'write',
20 'isReadable',
'read',
'getContents',
'getMetadata'];
31 $this->{
'_fn_' .
$name} = $fn;
41 throw new \BadMethodCallException(str_replace(
'_fn_',
'',
$name)
42 .
'() is not implemented in the FnStream');
50 if (isset($this->_fn_close)) {
51 call_user_func($this->_fn_close);
68 foreach (array_diff(self::$slots, array_keys(
$methods)) as $diff) {
77 return call_user_func($this->_fn___toString);
82 return call_user_func($this->_fn_close);
87 return call_user_func($this->_fn_detach);
92 return call_user_func($this->_fn_getSize);
97 return call_user_func($this->_fn_tell);
102 return call_user_func($this->_fn_eof);
107 return call_user_func($this->_fn_isSeekable);
112 call_user_func($this->_fn_rewind);
115 public function seek($offset, $whence = SEEK_SET)
117 call_user_func($this->_fn_seek, $offset, $whence);
122 return call_user_func($this->_fn_isWritable);
127 return call_user_func($this->_fn_write, $string);
132 return call_user_func($this->_fn_isReadable);
137 return call_user_func($this->_fn_read, $length);
142 return call_user_func($this->_fn_getContents);
147 return call_user_func($this->_fn_getMetadata,
$key);
An exception for terminatinating execution or to throw for unit testing.
Compose stream implementations based on a hash of functions.
__get($name)
Lazily determine which methods are not implemented.
detach()
Separates any underlying resources from the stream.
isReadable()
Returns whether or not the stream is readable.
close()
Closes the stream and any underlying resources.
isWritable()
Returns whether or not the stream is writable.
read($length)
Read data from the stream.
isSeekable()
Returns whether or not the stream is seekable.
getSize()
Get the size of the stream if known.
rewind()
Seek to the beginning of the stream.
static decorate(StreamInterface $stream, array $methods)
Adds custom functionality to an underlying stream by intercepting specific method calls.
__destruct()
The close method is called on the underlying stream only if possible.
getMetadata($key=null)
Get stream metadata as an associative array or retrieve a specific key.
eof()
Returns true if the stream is at the end of the stream.
__construct(array $methods)
write($string)
Write data to the stream.
tell()
Returns the current position of the file read/write pointer.
getContents()
Returns the remaining contents in a string.
seek($offset, $whence=SEEK_SET)
Seek to a position in the stream.
__toString()
Reads all data from the stream into a string, from the beginning to end.
$stream
PHP stream implementation.