class Stream implements StreamInterface, Stringable

Properties

protected int $size
protected bool $detached

Methods

__construct(string $contents = '')

Create a new stream instance.

string
__toString()

Reads all data from the stream into a string, from the beginning to end.

void
close()

Closes the stream and any underlying resources.

null|resource
detach()

Separates any underlying resources from the stream.

int|null
getSize()

Get the size of the stream if known.

int
tell()

Returns the current position of the file read/write pointer.

bool
eof()

Returns true if the stream is at the end of the stream.

bool
isSeekable()

Returns whether or not the stream is seekable.

void
seek(int $offset, int $whence = SEEK_SET)

Seek to a position in the stream.

void
rewind()

Seek to the beginning of the stream.

bool
isWritable()

Returns whether or not the stream is writable.

int
write(string $string)

Write data to the stream.

bool
isReadable()

Returns whether or not the stream is readable.

string
read(int $length)

Read data from the stream.

string
getContents()

Returns the remaining contents in a string.

mixed
getMetadata(string|null $key = null)

Get stream metadata as an associative array or retrieve a specific key.

Details

at line 21
__construct(string $contents = '')

Create a new stream instance.

Parameters

string $contents

at line 36
string __toString()

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.

at line 48
void close()

Closes the stream and any underlying resources.

Return Value

void

at line 59
null|resource detach()

Separates any underlying resources from the stream.

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

Return Value

null|resource

Underlying PHP stream, if any

at line 73
int|null getSize()

Get the size of the stream if known.

Return Value

int|null

returns the size in bytes if known, or null if unknown

at line 84
int tell()

Returns the current position of the file read/write pointer.

Return Value

int

Position of the file pointer

Exceptions

RuntimeException

at line 92
bool eof()

Returns true if the stream is at the end of the stream.

Return Value

bool

at line 104
bool isSeekable()

Returns whether or not the stream is seekable.

Return Value

bool

at line 121
void seek(int $offset, int $whence = SEEK_SET)

Seek to a position in the stream.

Parameters

int $offset

Stream offset

int $whence

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.

Return Value

void

Exceptions

RuntimeException

See also

http://www.php.net/manual/en/function.fseek.php

at line 135
void rewind()

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).

Return Value

void

Exceptions

RuntimeException

See also

http://www.php.net/manual/en/function.fseek.php
seek()

at line 143
bool isWritable()

Returns whether or not the stream is writable.

Return Value

bool

at line 155
int write(string $string)

Write data to the stream.

Parameters

string $string

the string that is to be written

Return Value

int

returns the number of bytes written to the stream

Exceptions

RuntimeException

at line 172
bool isReadable()

Returns whether or not the stream is readable.

Return Value

bool

at line 187
string read(int $length)

Read data from the stream.

Parameters

int $length

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 Value

string

returns the data read from the stream, or an empty string if no bytes are available

Exceptions

RuntimeException

at line 220
string getContents()

Returns the remaining contents in a string.

Return Value

string

Exceptions

RuntimeException

at line 239
mixed getMetadata(string|null $key = null)

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.

Parameters

string|null $key

Return Value

mixed

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.

See also

http://php.net/manual/en/function.stream-get-meta-data.php