Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 403]

(no description)

File Size: 158 lines (5 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

StreamInterface:: (15 methods):
  __toString()
  close()
  detach()
  getSize()
  tell()
  eof()
  isSeekable()
  seek()
  rewind()
  isWritable()
  write()
  isReadable()
  read()
  getContents()
  getMetadata()


Interface: StreamInterface  - X-Ref

Describes a data stream.

Typically, an instance will wrap a PHP stream; this interface provides
a wrapper around the most common operations, including serialization of
the entire stream to a string.
__toString()   X-Ref
Reads all data from the stream into a string, from the beginning to end.

This method MUST attempt to seek to the beginning of the stream before
reading data and read the stream until the end is reached.

Warning: This could attempt to load a large amount of data into memory.

This method MUST NOT raise an exception in order to conform with PHP's
string casting operations.

return: string

close()   X-Ref
Closes the stream and any underlying resources.

return: void

detach()   X-Ref
Separates any underlying resources from the stream.

After the stream has been detached, the stream is in an unusable state.

return: resource|null Underlying PHP stream, if any

getSize()   X-Ref
Get the size of the stream if known.

return: int|null Returns the size in bytes if known, or null if unknown.

tell()   X-Ref
Returns the current position of the file read/write pointer

return: int Position of the file pointer

eof()   X-Ref
Returns true if the stream is at the end of the stream.

return: bool

isSeekable()   X-Ref
Returns whether or not the stream is seekable.

return: bool

seek($offset, $whence = SEEK_SET)   X-Ref
Seek to a position in the stream.

param: int $offset Stream offset
param: int $whence Specifies how the cursor position will be calculated

rewind()   X-Ref
Seek to the beginning of the stream.

If the stream is not seekable, this method will raise an exception;
otherwise, it will perform a seek(0).


isWritable()   X-Ref
Returns whether or not the stream is writable.

return: bool

write($string)   X-Ref
Write data to the stream.

param: string $string The string that is to be written.
return: int Returns the number of bytes written to the stream.

isReadable()   X-Ref
Returns whether or not the stream is readable.

return: bool

read($length)   X-Ref
Read data from the stream.

param: int $length Read up to $length bytes from the object and return
return: string Returns the data read from the stream, or an empty string

getContents()   X-Ref
Returns the remaining contents in a string

return: string

getMetadata($key = null)   X-Ref
Get stream metadata as an associative array or retrieve a specific key.

The keys returned are identical to the keys returned from PHP's
stream_get_meta_data() function.

param: string $key Specific metadata to retrieve.
return: array|mixed|null Returns an associative array if no key is