18 private static $slots = [
'__toString',
'close',
'detach',
'rewind',
19 'getSize',
'tell',
'eof',
'isSeekable',
'seek',
'isWritable',
'write',
20 'isReadable',
'read',
'getContents',
'getMetadata'];
30 foreach ($methods as
$name => $fn) {
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) {
69 $methods[$diff] = [
$stream, $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);
eof()
Returns true if the stream is at the end of the stream.
tell()
Returns the current position of the file read/write pointer.
rewind()
Seek to the beginning of the stream.
isReadable()
Returns whether or not the stream is readable.
isSeekable()
Returns whether or not the stream is seekable.
static decorate(StreamInterface $stream, array $methods)
Adds custom functionality to an underlying stream by intercepting specific method calls...
detach()
Separates any underlying resources from the stream.
read($length)
Read data from the stream.
isWritable()
Returns whether or not the stream is writable.
__destruct()
The close method is called on the underlying stream only if possible.
$stream
PHP stream implementation.
__get($name)
Lazily determine which methods are not implemented.
__construct(array $methods)
getSize()
Get the size of the stream if known.
getContents()
Returns the remaining contents in a string.
close()
Closes the stream and any underlying resources.
Compose stream implementations based on a hash of functions.
getMetadata($key=null)
Get stream metadata as an associative array or retrieve a specific key.
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.
write($string)
Write data to the stream.