ResponseAdapter
API reference › PSR bridge › adapter › ResponseAdapter
Adapts Yii responses to PSR-7 responses.
ResponseInterface PSR-7 response contract.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Creates a new instance of the ResponseAdapter class. | ResponseAdapter |
toPsr7() | Converts the Yii Response instance to a PSR-7 ResponseInterface. | ResponseAdapter |
Method details
Section titled “Method details”__construct()
Section titled “__construct() ”public function __construct(yii2\extensions\psrbridge\http\Response $psrResponse, Psr\Http\Message\ResponseFactoryInterface $responseFactory, Psr\Http\Message\StreamFactoryInterface $streamFactory, yii\base\Security $security)Creates a new instance of the ResponseAdapter class.
Parameters
| Parameter | Type | Description |
|---|---|---|
$psrResponse | yii2\ | Yii Response instance to adapt. |
$responseFactory | Psr\ | PSR-7 ResponseFactoryInterface instance for response creation. |
$streamFactory | Psr\ | PSR-7 StreamFactoryInterface instance for body stream creation. |
$security | yii\ | Security component used to sign outgoing cookie values. |
toPsr7()
Section titled “toPsr7() ”public function toPsr7(): Psr\Http\Message\ResponseInterfaceConverts the Yii Response instance to a PSR-7 ResponseInterface.
Creates a new PSR-7 ResponseInterface using the configured response and stream factories, copying status code, status text, headers, cookies, and body content from the Yii Response component.
- All headers are transferred to the PSR-7 ResponseInterface, with multiple values preserved.
- Cookies are formatted and added as separate ‘Set-Cookie’ headers.
- File streaming is supported with HTTP range handling for efficient large file downloads.
- Response body is created from the Yii Response content or stream using the PSR-7 StreamFactoryInterface.
Returns
Psr\Http\Message\ResponseInterface: PSR-7 ResponseInterface instance with headers, cookies, and body content.
Throws
yii\base\InvalidConfigException: if the configuration is invalid or incomplete.