Skip to content
PHP Ecosystem
Explore

ResponseAdapter

API reference › PSR bridge › adapter › ResponseAdapter

final classyii2\extensions\psrbridge\adapter\ResponseAdapter
Sourcesrc/adapter/ResponseAdapter.php

Adapts Yii responses to PSR-7 responses.

ResponseInterface PSR-7 response contract.

MethodDescriptionDefined by
__construct()Creates a new instance of the ResponseAdapter class.ResponseAdapter
toPsr7()Converts the Yii Response instance to a PSR-7 ResponseInterface.ResponseAdapter
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

ParameterTypeDescription
$psrResponseyii2\extensions\psrbridge\http\ResponseYii Response instance to adapt.
$responseFactoryPsr\Http\Message\ResponseFactoryInterfacePSR-7 ResponseFactoryInterface instance for response creation.
$streamFactoryPsr\Http\Message\StreamFactoryInterfacePSR-7 StreamFactoryInterface instance for body stream creation.
$securityyii\base\SecuritySecurity component used to sign outgoing cookie values.
public function toPsr7(): Psr\Http\Message\ResponseInterface

Converts 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