Implementation of PSR HTTP streams.
This differs from Laminas\Diactoros\Callback stream in that it allows the use of echo inside the callback, and gracefully handles the callback not returning a string.
Ideally we can amend/update diactoros, but we need to figure that out with the diactoros project. Until then we'll use this shim to provide backwards compatibility with existing CakePHP apps.
callable|nullReads all data from the stream into a string, from the beginning to end.
Attach a new callback to the instance.
Closes the stream and any underlying resources.
Separates any underlying resources from the stream.
Returns true if the stream is at the end of the stream.
Returns the remaining contents in a string
Get stream metadata as an associative array or retrieve a specific key.
Get the size of the stream if known.
Returns whether or not the stream is readable.
Returns whether or not the stream is seekable.
Returns whether or not the stream is writable.
Read data from the stream.
Seek to the beginning of the stream.
Seek to a position in the stream.
Returns the current position of the file read/write pointer
Write data to the stream.
__construct(callable $callback)
callable $callback Exception\InvalidArgumentException__toString(): string
Reads all data from the stream into a string, from the beginning to end.
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.
stringattach(callable $callback): void
Attach a new callback to the instance.
callable $callback voidclose(): void
Closes the stream and any underlying resources.
voiddetach(): null|callable
Separates any underlying resources from the stream.
After the stream has been detached, the stream is in an unusable state.
null|callableeof(): bool
Returns true if the stream is at the end of the stream.
boolgetContents(): string
Returns the remaining contents in a string
stringgetMetadata(string $key = null): array|mixed|null
Get stream metadata as an associative array or retrieve a specific key.
The keys returned are identical to the keys returned from PHP's stream_get_meta_data() function.
string $key optional array|mixed|nullgetSize(): ?int
Get the size of the stream if known.
?intisReadable(): bool
Returns whether or not the stream is readable.
boolisSeekable(): bool
Returns whether or not the stream is seekable.
boolisWritable(): bool
Returns whether or not the stream is writable.
boolread(int $length): string
Read data from the stream.
int $length stringrewind(): void
Seek to the beginning of the stream.
If the stream is not seekable, this method will raise an exception; otherwise, it will perform a seek(0).
voidseek(int $offset, int $whence = SEEK_SET): void
Seek to a position in the stream.
int $offset int $whence optional voidtell(): int
Returns the current position of the file read/write pointer
intwrite(string $string): void
Write data to the stream.
string $string voidcallable|null
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/class-Cake.Http.CallbackStream.html