Skip to content
PHP Ecosystem
Explore

ResponseBody

API reference › RoadRunner › ResponseBody

final classyii2\extensions\roadrunner\ResponseBody
ImplementsPsr\Http\Message\StreamInterface
Sourcesrc/ResponseBody.php

Retains failures from streaming read() and eof() calls that an emitter may consume.

MethodDescriptionDefined 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
public function __construct(Psr\Http\Message\StreamInterface $stream)

Creates a new instance of the ResponseBody class.

Parameters

ParameterTypeDescription
$streamPsr\Http\Message\StreamInterfaceResponse body stream to delegate to.
public function __toString(): string

Returns the entire contents of the wrapped stream.

Returns

string

public function close(): void

Closes the wrapped stream and its underlying resources.

public function detach(): resource|null

Detaches the underlying resource from the wrapped stream.

Returns

resource|null

public function eof(): bool

Returns 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.
public function getContents(): string

Returns the remaining contents of the wrapped stream.

Returns

string

public function getFailure(): Throwable|null

Returns the failure even when the emitter returned normally after consuming it.

Returns

Throwable|null

public function getMetadata(string|null $key = null): mixed

Returns the wrapped stream metadata, or the value for $key.

Parameters

ParameterTypeDescription
$keystring|nullMetadata key to retrieve, or null for all metadata.

Returns

mixed

public function getSize(): int|null

Returns the size of the wrapped stream in bytes, or null when it is unknown.

Returns

int|null

public function isReadable(): bool

Returns whether the wrapped stream is readable.

Returns

bool

public function isSeekable(): bool

Returns whether the wrapped stream is seekable.

Returns

bool

public function isWritable(): bool

Returns whether the wrapped stream is writable.

Returns

bool

public function read(int $length): string

Reads up to $length bytes from the wrapped stream and retains any failure for getFailure().

Parameters

ParameterTypeDescription
$lengthintMaximum number of bytes to read.

Returns

string

Throws

  • Throwable: if the wrapped stream fails; the same instance is retained before it is rethrown.
public function rewind(): void

Seeks the wrapped stream to its beginning.

public function seek(int $offset, int $whence = \yii2\extensions\roadrunner\SEEK_SET): void

Seeks the wrapped stream to a position.

Parameters

ParameterTypeDescription
$offsetintStream offset.
$whenceintOffset calculation mode, as accepted by fseek().
public function tell(): int

Returns the current position of the wrapped stream pointer.

Returns

int

public function write(string $string): int

Writes data to the wrapped stream.

Parameters

ParameterTypeDescription
$stringstringData to write.

Returns

int: Number of bytes written.