SDK for PHP V3

CachingStream
in package
implements StreamInterface Uses StreamDecoratorTrait, NonSerializableStreamTrait

FinalYes

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

Table of Contents

Interfaces

StreamInterface
Describes a data stream.

Methods

__call()  : mixed
Allow decorators to implement custom methods
__construct()  : mixed
We will treat the buffer object as the body of the stream
__get()  : StreamInterface
Magic method used to create a new stream if streams are not added in the constructor of a decorator (e.g., LazyOpenStream).
__toString()  : string
close()  : void
Close the remote stream and any attached cache 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
getMetadata()  : mixed
getSize()  : int|null
Get the size of the stream if known.
isReadable()  : bool
isSeekable()  : bool
isWritable()  : bool
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
write()  : int
Write data to the stream.

Methods

__call()

Allow decorators to implement custom methods

public __call(string $method, array<string|int, mixed> $args) : mixed
Parameters
$method : string
$args : array<string|int, mixed>

__construct()

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

public __construct(StreamInterface $stream[, StreamInterface $target = null ]) : mixed
Parameters
$stream : StreamInterface

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

$target : StreamInterface = null

Optionally specify where data is cached. Defaults to a "php://temp" stream. A custom target is used as a random-access byte buffer to replay the remote stream, so it must be readable, writable, and seekable, report an accurate position and size, and store writes losslessly. Lossy or non-seekable streams such as BufferStream and DroppingStream are not valid targets.

__get()

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

public __get(string $name) : StreamInterface
Parameters
$name : string
Return values
StreamInterface

__toString()

public __toString() : string
Return values
string

close()

Close the remote stream and any attached cache stream.

public close() : void

detach()

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
bool

getContents()

public getContents() : string
Return values
string

getMetadata()

public getMetadata([string|null $key = null ]) : mixed
Parameters
$key : string|null = null

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

public isReadable() : bool
Return values
bool

isSeekable()

public isSeekable() : bool
Return values
bool

isWritable()

public isWritable() : bool
Return values
bool

read()

Read data from the stream.

public read(int $length) : string
Parameters
$length : int

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(int $offset[, int $whence = SEEK_SET ]) : void
Parameters
$offset : int

Stream offset

$whence : int = 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()

public tell() : int
Return values
int

write()

Write data to the stream.

public write(string $string) : int
Parameters
$string : string

The string that is to be written.

Return values
int —

Returns the number of bytes written to the stream.

<-- modeled_exceptions -->
On this page