\GuzzleHttp\Psr7CachingStream

Stream decorator that can cache previously read bytes from a sequentially read stream.

Summary

Methods
Properties
Constants
__construct()
__get()
__toString()
getContents()
__call()
close()
getMetadata()
detach()
getSize()
eof()
tell()
isReadable()
isWritable()
isSeekable()
rewind()
seek()
read()
write()
No public properties found
No constants found
createStream()
No protected properties found
N/A
cacheEntireStream()
$remoteStream
$skipReadBytes
N/A

Properties

$remoteStream

$remoteStream : \Psr\Http\Message\StreamInterface

Type

StreamInterface — Stream being wrapped

$skipReadBytes

$skipReadBytes : int

Type

int — Number of bytes to skip reading due to a write on the buffer

Methods

__construct()

__construct(\Psr\Http\Message\StreamInterface  $stream, \Psr\Http\Message\StreamInterface  $target = null) : mixed

We will treat the buffer object as the body of the stream

Parameters

\Psr\Http\Message\StreamInterface $stream

Stream to cache. The cursor is assumed to be at the beginning of the stream.

\Psr\Http\Message\StreamInterface $target

Optionally specify where data is cached

Returns

mixed —

__get()

__get(string  $name) : \Psr\Http\Message\StreamInterface

Magic method used to create a new stream if streams are not added in the constructor of a decorator (e.g., LazyOpenStream).

Parameters

string $name

Name of the property (allows "stream" only).

Returns

\Psr\Http\Message\StreamInterface —

__toString()

__toString() : mixed

Returns

mixed —

getContents()

getContents() : mixed

Returns

mixed —

__call()

__call(string  $method, array  $args) : mixed

Allow decorators to implement custom methods

Parameters

string $method

Missing method name

array $args

Method arguments

Returns

mixed —

close()

close() : void

Close both the remote stream and buffer stream

getMetadata()

getMetadata(mixed  $key = null) : mixed

Parameters

mixed $key

Returns

mixed —

detach()

detach() : mixed

Returns

mixed —

getSize()

getSize() : int|null

Get the size of the stream if known.

Returns

int|null —

Returns the size in bytes if known, or null if unknown.

eof()

eof() : bool

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

Returns

bool —

tell()

tell() : mixed

Returns

mixed —

isReadable()

isReadable() : mixed

Returns

mixed —

isWritable()

isWritable() : mixed

Returns

mixed —

isSeekable()

isSeekable() : mixed

Returns

mixed —

rewind()

rewind() : mixed

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

Returns

mixed —

seek()

seek(mixed  $offset, mixed  $whence = SEEK_SET) : mixed

Seek to a position in the stream.

Parameters

mixed $offset

Stream offset

mixed $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.

Returns

mixed —

read()

read(mixed  $length) : string

Read data from the stream.

Parameters

mixed $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.

Returns

string —

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

write()

write(mixed  $string) : int

Write data to the stream.

Parameters

mixed $string

The string that is to be written.

Returns

int —

Returns the number of bytes written to the stream.

createStream()

createStream() : \Psr\Http\Message\StreamInterface

Implement in subclasses to dynamically create streams when requested.

Throws

\BadMethodCallException

Returns

\Psr\Http\Message\StreamInterface —

cacheEntireStream()

cacheEntireStream() : mixed

Returns

mixed —