Documentation

CachingStream
in package
implements StreamInterface Uses StreamDecoratorTrait

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

Tags
final

Interfaces, Classes and Traits

StreamInterface
Describes a data stream.

Table of Contents

$remoteStream  : StreamInterface
$skipReadBytes  : int
__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()  : mixed
close()  : void
Close both the remote stream and buffer stream
detach()  : mixed
eof()  : bool
Returns true if the stream is at the end of the stream.
getContents()  : mixed
getMetadata()  : mixed
getSize()  : int|null
Get the size of the stream if known.
isReadable()  : mixed
isSeekable()  : mixed
isWritable()  : mixed
read()  : string
Read data from the stream.
rewind()  : mixed
Seek to the beginning of the stream.
seek()  : mixed
Seek to a position in the stream.
tell()  : mixed
write()  : int
Write data to the stream.
createStream()  : StreamInterface
Implement in subclasses to dynamically create streams when requested.
cacheEntireStream()  : mixed

Properties

Methods

__call()

Allow decorators to implement custom methods

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

Missing method name

$args : array<string|int, mixed>

Method arguments

Return values
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

Return values
mixed

__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

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

Return values
StreamInterface

close()

Close both the remote stream and buffer stream

public close() : void
Return values
void

eof()

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

public eof() : bool
Return values
bool

getMetadata()

public getMetadata([mixed $key = null ]) : mixed
Parameters
$key : mixed = null
Return values
mixed

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.

read()

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

If the stream is not seekable, this method will raise an exception; otherwise, it will perform a seek(0).

Return values
mixed

seek()

Seek to a position in the stream.

public seek(mixed $offset[, mixed $whence = SEEK_SET ]) : mixed
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.

Return values
mixed

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.

cacheEntireStream()

private cacheEntireStream() : mixed
Return values
mixed

Search results