Reads from multiple streams, one after the other.
This is a read-only stream decorator.
- Full name:
\GuzzleHttp\Psr7\AppendStream
- This class is marked as final and can't be subclassed
- This class implements:
\Psr\Http\Message\StreamInterface
- This class is a Final class
private \Psr\Http\Message\StreamInterface[] $streams
private bool $seekable
private int $current
private int $pos
public __construct(\Psr\Http\Message\StreamInterface[] $streams = []): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$streams |
\Psr\Http\Message\StreamInterface[] | Streams to decorate. Each stream must be readable. |
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.
Add a stream to the AppendStream
public addStream(\Psr\Http\Message\StreamInterface $stream): void
Parameters:
Parameter | Type | Description |
---|---|---|
$stream |
\Psr\Http\Message\StreamInterface | Stream to append. Must be readable. |
Returns the remaining contents in a string
public getContents(): string
Closes each attached stream.
public close(): void
Detaches each attached stream.
public detach(): resource|null
Returns null as it's not clear which underlying stream resource to return.
Return Value:
Underlying PHP stream, if any
Returns the current position of the file read/write pointer
public tell(): int
Return Value:
Position of the file pointer
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 Value:
Returns the size in bytes if known, or null if unknown.
Returns true if the stream is at the end of the stream.
public eof(): bool
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).
Attempts to seek to the given position. Only supports SEEK_SET.
public seek(mixed $offset, mixed $whence = SEEK_SET): void
Parameters:
Parameter | Type | Description |
---|---|---|
$offset |
mixed | Stream offset |
$whence |
mixed | 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 tooffset bytes SEEK_CUR: Set position to current location plus offset SEEK_END: Set position to end-of-stream plus offset. |
Reads from all of the appended streams until the length is met or EOF.
public read(mixed $length): string
Parameters:
Parameter | Type | Description |
---|---|---|
$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 Value:
Returns the data read from the stream, or an empty string if no bytes are available.
Returns whether or not the stream is readable.
public isReadable(): bool
Returns whether or not the stream is writable.
public isWritable(): bool
Returns whether or not the stream is seekable.
public isSeekable(): bool
Write data to the stream.
public write(mixed $string): int
Parameters:
Parameter | Type | Description |
---|---|---|
$string |
mixed | The string that is to be written. |
Return Value:
Returns the number of bytes written to the stream.
Get stream metadata as an associative array or retrieve a specific key.
public getMetadata(mixed $key = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$key |
mixed | Specific metadata to retrieve. |