LimitStream
in package
implements
StreamInterface
uses
StreamDecoratorTrait
Decorator used to return only a subset of a stream.
Table of Contents
Interfaces
- StreamInterface
- Describes a data stream.
Properties
- $limit : int
- $offset : int
- $stream : StreamInterface
Methods
- __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
- 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
$stream
private
StreamInterface
$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()
public
__construct(StreamInterface $stream[, int $limit = -1 ][, int $offset = 0 ]) : 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 = 0
-
Position to seek to before reading (only works on seekable streams).
__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
stringclose()
public
close() : void
detach()
public
detach() : mixed
eof()
Returns true if the stream is at the end of the stream.
public
eof() : bool
Return values
boolgetContents()
public
getContents() : string
Return values
stringgetMetadata()
public
getMetadata([mixed $key = null ]) : mixed
Parameters
- $key : mixed = null
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.
isReadable()
public
isReadable() : bool
Return values
boolisSeekable()
public
isSeekable() : bool
Return values
boolisWritable()
public
isWritable() : bool
Return values
boolread()
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()
public
rewind() : void
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.
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.
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
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
intcreateStream()
Implement in subclasses to dynamically create streams when requested.
protected
createStream() : StreamInterface