ResponseBody
API reference › RoadRunner › ResponseBody
Retains failures from streaming read() and eof() calls that an emitter may consume.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Creates a new instance of the ResponseBody class. | ResponseBody |
__toString() | Returns the entire contents of the wrapped stream. | ResponseBody |
close() | Closes the wrapped stream and its underlying resources. | ResponseBody |
detach() | Detaches the underlying resource from the wrapped stream. | ResponseBody |
eof() | Returns whether the wrapped stream is at its end and retains any failure for getFailure(). | ResponseBody |
getContents() | Returns the remaining contents of the wrapped stream. | ResponseBody |
getFailure() | Returns the failure even when the emitter returned normally after consuming it. | ResponseBody |
getMetadata() | Returns the wrapped stream metadata, or the value for $key. | ResponseBody |
getSize() | Returns the size of the wrapped stream in bytes, or null when it is unknown. | ResponseBody |
isReadable() | Returns whether the wrapped stream is readable. | ResponseBody |
isSeekable() | Returns whether the wrapped stream is seekable. | ResponseBody |
isWritable() | Returns whether the wrapped stream is writable. | ResponseBody |
read() | Reads up to $length bytes from the wrapped stream and retains any failure for getFailure(). | ResponseBody |
rewind() | Seeks the wrapped stream to its beginning. | ResponseBody |
seek() | Seeks the wrapped stream to a position. | ResponseBody |
tell() | Returns the current position of the wrapped stream pointer. | ResponseBody |
write() | Writes data to the wrapped stream. | ResponseBody |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(Psr\Http\Message\StreamInterface $stream)Creates a new instance of the ResponseBody class.
Parameters
| Parameter | Type | Description |
|---|---|---|
$stream | Psr\ | Response body stream to delegate to. |
__toString()
Section titled “__toString() ”public function __toString(): stringReturns the entire contents of the wrapped stream.
Returns
string
close()
Section titled “close() ”public function close(): voidCloses the wrapped stream and its underlying resources.
detach()
Section titled “detach() ”public function detach(): resource|nullDetaches the underlying resource from the wrapped stream.
Returns
resource|null
eof()
Section titled “eof() ”public function eof(): boolReturns whether the wrapped stream is at its end and retains any failure for getFailure().
Returns
bool
Throws
Throwable: if the wrapped stream fails; the same instance is retained before it is rethrown.
getContents()
Section titled “getContents() ”public function getContents(): stringReturns the remaining contents of the wrapped stream.
Returns
string
getFailure()
Section titled “getFailure() ”public function getFailure(): Throwable|nullReturns the failure even when the emitter returned normally after consuming it.
Returns
Throwable|null
getMetadata()
Section titled “getMetadata() ”public function getMetadata(string|null $key = null): mixedReturns the wrapped stream metadata, or the value for $key.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string| | Metadata key to retrieve, or null for all metadata. |
Returns
mixed
getSize()
Section titled “getSize() ”public function getSize(): int|nullReturns the size of the wrapped stream in bytes, or null when it is unknown.
Returns
int|null
isReadable()
Section titled “isReadable() ”public function isReadable(): boolReturns whether the wrapped stream is readable.
Returns
bool
isSeekable()
Section titled “isSeekable() ”public function isSeekable(): boolReturns whether the wrapped stream is seekable.
Returns
bool
isWritable()
Section titled “isWritable() ”public function isWritable(): boolReturns whether the wrapped stream is writable.
Returns
bool
read()
Section titled “read() ”public function read(int $length): stringReads up to $length bytes from the wrapped stream and retains any failure for getFailure().
Parameters
| Parameter | Type | Description |
|---|---|---|
$length | int | Maximum number of bytes to read. |
Returns
string
Throws
Throwable: if the wrapped stream fails; the same instance is retained before it is rethrown.
rewind()
Section titled “rewind() ”public function rewind(): voidSeeks the wrapped stream to its beginning.
seek()
Section titled “seek() ”public function seek(int $offset, int $whence = \yii2\extensions\roadrunner\SEEK_SET): voidSeeks the wrapped stream to a position.
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | int | Stream offset. |
$whence | int | Offset calculation mode, as accepted by fseek(). |
tell()
Section titled “tell() ”public function tell(): intReturns the current position of the wrapped stream pointer.
Returns
int
write()
Section titled “write() ”public function write(string $string): intWrites data to the wrapped stream.
Parameters
| Parameter | Type | Description |
|---|---|---|
$string | string | Data to write. |
Returns
int: Number of bytes written.