SDK for PHP 3.x

AppendStream
in package
implements StreamInterface

FinalYes

Reads from multiple streams, one after the other.

This is a read-only stream decorator.

Table of Contents

Interfaces

StreamInterface
Describes a data stream.

Methods

__construct()  : mixed
__toString()  : string
Reads all data from the stream into a string, from the beginning to end.
addStream()  : void
Add a stream to the AppendStream
close()  : void
Closes each attached stream.
detach()  : resource|null
Detaches each attached stream.
eof()  : bool
Returns true if the stream is at the end of the stream.
getContents()  : string
Returns the remaining contents in a string
getMetadata()  : mixed
Get stream metadata as an associative array or retrieve a specific key.
getSize()  : int|null
Tries to calculate the size by adding the size of each stream.
isReadable()  : bool
Returns whether or not the stream is readable.
isSeekable()  : bool
Returns whether or not the stream is seekable.
isWritable()  : bool
Returns whether or not the stream is writable.
read()  : string
Reads from all of the appended streams until the length is met or EOF.
rewind()  : void
Seek to the beginning of the stream.
seek()  : void
Attempts to seek to the given position. Only supports SEEK_SET.
tell()  : int
Returns the current position of the file read/write pointer
write()  : int
Write data to the stream.

Methods

__construct()

public __construct([array<string|int, StreamInterface$streams = [] ]) : mixed
Parameters
$streams : array<string|int, StreamInterface> = []

Streams to decorate. Each stream must be readable.

__toString()

Reads all data from the stream into a string, from the beginning to end.

public __toString() : string

This method MUST attempt to seek to the beginning of the stream before reading data and read the stream until the end is reached.

Warning: This could attempt to load a large amount of data into memory.

This method MUST NOT raise an exception in order to conform with PHP's string casting operations.

Return values
string

addStream()

Add a stream to the AppendStream

public addStream(StreamInterface $stream) : void
Parameters
$stream : StreamInterface

Stream to append. Must be readable.

Tags
throws
InvalidArgumentException

if the stream is not readable

close()

Closes each attached stream.

public close() : void

detach()

Detaches each attached stream.

public detach() : resource|null

Returns null as it's not clear which underlying stream resource to return.

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

Returns the remaining contents in a string

public getContents() : string
Return values
string

getMetadata()

Get stream metadata as an associative array or retrieve a specific key.

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

Specific metadata to retrieve.

getSize()

Tries to calculate the size by adding the size of each stream.

public getSize() : int|null

If any of the streams do not return a valid number, then the size of the append stream cannot be determined and null is returned.

Return values
int|null

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

isReadable()

Returns whether or not the stream is readable.

public isReadable() : bool
Return values
bool

isSeekable()

Returns whether or not the stream is seekable.

public isSeekable() : bool
Return values
bool

isWritable()

Returns whether or not the stream is writable.

public isWritable() : bool
Return values
bool

read()

Reads from all of the appended streams until the length is met or EOF.

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

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

seek()

Attempts to seek to the given position. Only supports SEEK_SET.

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.

tell()

Returns the current position of the file read/write pointer

public tell() : int
Return values
int

Position of the file pointer

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.

On this page