CallbackStream
in package
implements
StreamInterface, Stringable
Implementation of PSR HTTP streams
Table of Contents
Interfaces
- StreamInterface
- Describes a data stream.
- Stringable
Properties
- $callback : callable|null
Methods
- __construct() : mixed
- __toString() : string
- Reads all data from the stream into a string, from the beginning to end.
- attach() : void
- Attach a new callback to the instance.
- close() : void
- Closes the stream and any underlying resources.
- detach() : null|callable
- Separates any underlying resources from the stream.
- eof() : bool
- Returns true if the stream is at the end of the stream.
- getContents() : string
- Returns the remaining contents in a string
- getMetadata() : array<string|int, mixed>|mixed|null
- Get stream metadata as an associative array or retrieve a specific key.
- getSize() : int|null
- Get the size of the stream if known.
- isReadable() : bool
- Returns whether or not the stream is readable.
- isSeekable() : bool
- Returns whether or not the stream is seekable.
- isWritable() : bool
- Returns whether or not the stream is writable.
- read() : string
- Read data from the stream.
- rewind() : void
- Seek to the beginning of the stream.
- seek() : void
- Seek to a position in the stream.
- tell() : int
- Returns the current position of the file read/write pointer
- write() : int
- Write data to the stream.
Properties
$callback
protected
callable|null
$callback
Methods
__construct()
public
__construct(callable $callback) : mixed
Parameters
- $callback : callable
Tags
__toString()
Reads all data from the stream into a string, from the beginning to end.
public
__toString() : string
Return values
stringattach()
Attach a new callback to the instance.
public
attach(callable $callback) : void
Parameters
- $callback : callable
close()
Closes the stream and any underlying resources.
public
close() : void
detach()
Separates any underlying resources from the stream.
public
detach() : null|callable
Return values
null|callableeof()
Returns true if the stream is at the end of the stream.
public
eof() : bool
Return values
boolgetContents()
Returns the remaining contents in a string
public
getContents() : string
Return values
stringgetMetadata()
Get stream metadata as an associative array or retrieve a specific key.
public
getMetadata([mixed $key = null ]) : array<string|int, mixed>|mixed|null
Parameters
- $key : mixed = null
-
Specific metadata to retrieve.
Return values
array<string|int, mixed>|mixed|null —Returns an associative array if no key is provided. Returns a specific key value if a key is provided and the value is found, or null if the key is not found.
getSize()
Get the size of the stream if known.
public
getSize() : int|null
Return values
int|null —Returns the size in bytes if known, or null if unknown.
isReadable()
Returns whether or not the stream is readable.
public
isReadable() : bool
Return values
boolisSeekable()
Returns whether or not the stream is seekable.
public
isSeekable() : bool
Return values
boolisWritable()
Returns whether or not the stream is writable.
public
isWritable() : bool
Return values
boolread()
Read data from the stream.
public
read(mixed $length) : string
Parameters
- $length : mixed
-
Read up to $length bytes from the object and return them. Fewer than $length bytes may be returned if underlying stream call returns fewer bytes.
Return values
string —Returns the data read from the stream, or an empty string if no bytes are available.
rewind()
Seek to the beginning of the stream.
public
rewind() : void
seek()
Seek to a position in the stream.
public
seek(int $offset[, int $whence = SEEK_SET ]) : void
Parameters
- $offset : int
- $whence : int = SEEK_SET
tell()
Returns the current position of the file read/write pointer
public
tell() : int
Return values
int —Position of the file pointer
write()
Write data to the stream.
public
write(mixed $string) : int
Parameters
- $string : mixed
-
The string that is to be written.
Return values
int —Returns the number of bytes written to the stream.