Documentation

LimitStream
in package
implements StreamInterface Uses StreamDecoratorTrait

Decorator used to return only a subset of a stream.

Interfaces, Classes, Traits and Enums

StreamInterface
Describes a data stream.

Table of Contents

$limit  : int
$offset  : int
$stream  : StreamInterface
__call()  : mixed
Allow decorators to implement custom methods
__construct()  : mixed
__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
detach()  : mixed
eof()  : bool
Returns true if the stream is at the end of the stream.
getContents()  : string
getMetadata()  : mixed
{@inheritdoc}
getSize()  : int|null
Returns the size of the limited subset of data
isReadable()  : bool
isSeekable()  : bool
isWritable()  : bool
read()  : string
Read data from the stream.
rewind()  : void
seek()  : void
Allow for a bounded seek on the read limited stream
setLimit()  : void
Set the limit of bytes that the decorator allows to be read from the stream.
setOffset()  : void
Set the offset to start limiting from
tell()  : int
Give a relative tell()
write()  : int
createStream()  : StreamInterface
Implement in subclasses to dynamically create streams when requested.

Properties

$limit

private int $limit

Limit the number of bytes that can be read

$offset

private int $offset

Offset to start reading from

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

__construct()

public __construct(StreamInterface $stream[, int $limit = -1 ], int $offset) : mixed
Parameters
$stream : StreamInterface

Stream to wrap

$limit : int = -1

Total number of bytes to allow to be read from the stream. Pass -1 for no limit.

$offset : int

Position to seek to before reading (only works on seekable streams).

Return values
mixed

eof()

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

public eof() : bool
Return values
bool

getMetadata()

{@inheritdoc}

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

getSize()

Returns the size of the limited subset of data

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.

seek()

Allow for a bounded seek on the read limited 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.

Return values
void

setLimit()

Set the limit of bytes that the decorator allows to be read from the stream.

public setLimit(int $limit) : void
Parameters
$limit : int

Number of bytes to allow to be read from the stream. Use -1 for no limit.

Return values
void

setOffset()

Set the offset to start limiting from

public setOffset(int $offset) : void
Parameters
$offset : int

Offset to seek to and begin byte limiting from

Tags
throws
RuntimeException

if the stream cannot be seeked.

Return values
void

tell()

Give a relative tell()

public tell() : int
Return values
int

Position of the file pointer

write()

public write(mixed $string) : int
Parameters
$string : mixed
Return values
int

Search results