Stream
in package
implements
StreamInterface
uses
StreamTrait
Tags
Table of Contents
Interfaces
- StreamInterface
- Describes a data stream.
Constants
- READ_WRITE_HASH = ['read' => ['r' => true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true, 'rb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true, 'c+b' => true, 'rt' => true, 'w+t' => true, 'r+t' => true, 'x+t' => true, 'c+t' => true, 'a+' => true], 'write' => ['w' => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true, 'c+' => true, 'wb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true, 'c+b' => true, 'w+t' => true, 'r+t' => true, 'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true]]
Properties
- $readable : bool
- $seekable : bool
- $size : int|null
- $stream : resource|null
- $uri : array<string|int, mixed>|mixed|void|bool|null
- $writable : bool
Methods
- __construct() : mixed
- __destruct() : mixed
- Closes the stream when the destructed.
- close() : void
- Closes the stream and any underlying resources.
- create() : StreamInterface
- Creates a new PSR-7 stream.
- detach() : resource|null
- 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() : mixed
- 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.
- getUri() : mixed
- openZvalStream() : mixed
Constants
READ_WRITE_HASH
private
array<string|int, mixed>
READ_WRITE_HASH
= ['read' => ['r' => true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true, 'rb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true, 'c+b' => true, 'rt' => true, 'w+t' => true, 'r+t' => true, 'x+t' => true, 'c+t' => true, 'a+' => true], 'write' => ['w' => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true, 'c+' => true, 'wb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true, 'c+b' => true, 'w+t' => true, 'r+t' => true, 'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true]]
Hash of readable and writable stream types
Properties
$readable
private
bool
$readable
$seekable
private
bool
$seekable
$size
private
int|null
$size
$stream
private
resource|null
$stream
A resource reference
$uri
private
array<string|int, mixed>|mixed|void|bool|null
$uri
$writable
private
bool
$writable
Methods
__construct()
public
__construct(resource $body) : mixed
Parameters
- $body : resource
__destruct()
Closes the stream when the destructed.
public
__destruct() : mixed
close()
Closes the stream and any underlying resources.
public
close() : void
create()
Creates a new PSR-7 stream.
public
static create([string|resource|StreamInterface $body = '' ]) : StreamInterface
Parameters
- $body : string|resource|StreamInterface = ''
Tags
Return values
StreamInterfacedetach()
Separates any underlying resources from the stream.
public
detach() : resource|null
After the stream has been detached, the stream is in an unusable state.
Return values
resource|null —Underlying PHP stream, if any
eof()
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 ]) : mixed
Parameters
- $key : mixed = null
-
Specific metadata to retrieve.
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
If the stream is not seekable, this method will raise an exception; otherwise, it will perform a seek(0).
seek()
Seek to a position in the stream.
public
seek(mixed $offset[, mixed $whence = SEEK_SET ]) : void
Parameters
- $offset : mixed
-
Stream offset
- $whence : mixed = SEEK_SET
-
Specifies how the cursor position will be calculated based on the seek offset. Valid values are identical to the built-in PHP $whence values for
fseek(). SEEK_SET: Set position equal to offset bytes SEEK_CUR: Set position to current location plus offset SEEK_END: Set position to end-of-stream plus offset.
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.
getUri()
private
getUri() : mixed
openZvalStream()
private
static openZvalStream(string $body) : mixed
Parameters
- $body : string