Response
API reference › PSR bridge › http › Response
Extends Yii response handling with PSR-7 response conversion.
ResponseAdapter Yii response to PSR-7 response adapter.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$acceptMimeType | string| | The MIME type (e.g. application/json) from the request ACCEPT header chosen for this response. Default: null. | yii\ |
$acceptParams | array | The parameters (e.g. ['q' => 1,) associated with the chosen MIME type. Default: []. | yii\ |
$behaviors read-only | array<yii\<static>> | List of behaviors attached to this component. | yii\ |
$charset | string| | The charset of the text response. Default: null. | yii\ |
$content | string| | The response content. Default: null. | yii\ |
$cookies read-only | yii\ | The cookie collection. | yii\ |
$cookieValidationKey | string | A secret key used for cookie validation. Default: ''. | Response |
$data | mixed | The original response data. Default: null. | yii\ |
$downloadHeaders write-only | string | The attachment file name. | yii\ |
$enableCookieValidation | bool | Whether to sign outgoing cookie values with $cookieValidationKey. Default: false. | Response |
$exitStatus | int | The exit status. Default: 0. | yii\ |
$format | string | The response format. Default: self::FORMAT_HTML. | yii\ |
$formatters | array | The formatters for converting data into the response content of the specified $format. Default: []. | yii\ |
$headers read-only | yii\ | The header collection. | yii\ |
$httpStatuses static | array | List of HTTP status codes and the corresponding texts Default: [100 => 'Continue',. | yii\ |
$isClientError read-only | bool | Whether this response indicates a client error. | yii\ |
$isEmpty read-only | bool | Whether this response is empty. | yii\ |
$isForbidden read-only | bool | Whether this response indicates the current request is forbidden. | yii\ |
$isInformational read-only | bool | Whether this response is informational. | yii\ |
$isInvalid read-only | bool | Whether this response has a valid $statusCode. | yii\ |
$isNotFound read-only | bool | Whether this response indicates the currently requested resource is not found. | yii\ |
$isOk read-only | bool | Whether this response is OK. | yii\ |
$isRedirection read-only | bool | Whether this response is a redirection. | yii\ |
$isSent | bool | Whether the response has been sent. Default: false. | yii\ |
$isServerError read-only | bool | Whether this response indicates a server error. | yii\ |
$isSuccessful read-only | bool | Whether this response is successful. | yii\ |
$psr7Response read-only | Psr\ | PSR-7 ResponseInterface instance representing the current Yii Response. | Response |
$statusCode | int | The HTTP status code to send with the response. | yii\ |
$statusCodeByException write-only | Throwable | The exception object. | yii\ |
$statusText | string | The HTTP status description that comes together with the status code. Default: 'OK'. | yii\ |
$stream | resource| | The stream to be sent. Default: null. | yii\ |
$version | string| | The version of the HTTP protocol to use. Default: null. | yii\ |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__clone() | This method is called after the object is created by cloning an existing one. | yii\ |
__get() | Returns the value of a component property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets the value of a component property. | yii\ |
__unset() | Sets a component property to be null. | yii\ |
attachBehavior() | Attaches a behavior to this component. | yii\ |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\ |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
captureSessionCookie() | Queues the current session ID, including rotation followed by an explicit close. | Response |
className() static | Returns the fully qualified name of this class. | yii\ |
clear() | Clears the headers, cookies, content, status code of the response. | yii\ |
clearOutputBuffers() | Removes all existing output buffers. | yii\ |
completeSend() | Completes the Yii response send lifecycle after the runtime emits the PSR-7 body. | Response |
detachBehavior() | Detaches a behavior from the component. | yii\ |
detachBehaviors() | Detaches all behaviors from the component. | yii\ |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\ |
getBehavior() | Returns the named behavior object. | yii\ |
getBehaviors() | Returns all behaviors attached to this component. | yii\ |
getCookies() | Returns the cookie collection. | yii\ |
getHeaders() | Returns the header collection. | yii\ |
getIsClientError() | yii\ | |
getIsEmpty() | yii\ | |
getIsForbidden() | yii\ | |
getIsInformational() | yii\ | |
getIsInvalid() | yii\ | |
getIsNotFound() | yii\ | |
getIsOk() | yii\ | |
getIsRedirection() | yii\ | |
getIsServerError() | yii\ | |
getIsSuccessful() | yii\ | |
getPsr7Response() | Converts the Yii Response component to a PSR-7 ResponseInterface instance. | Response |
getStatusCode() | yii\ | |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\ |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\ |
init() | Initializes this component. | yii\ |
off() | Detaches an existing event handler from this component. | yii\ |
on() | Attaches an event handler to an event. | yii\ |
redirect() | Redirects the browser to the specified URL. | yii\ |
refresh() | Refreshes the current page. | yii\ |
send() | Sends the response to the client. | yii\ |
sendContentAsFile() | Sends the specified content as a file to the browser. | yii\ |
sendFile() | Sends a file to the browser. | yii\ |
sendStreamAsFile() | Sends the specified stream as a file to the browser. | yii\ |
setDownloadHeaders() | Sets a default set of HTTP headers for file downloading purpose. | yii\ |
setStatusCode() | Sets the response status code. | yii\ |
setStatusCodeByException() | Sets the response status code based on the exception. | yii\ |
trigger() | Triggers an event. | yii\ |
xSendFile() | Sends existing file to a browser as a download using x-sendfile. | yii\ |
defaultFormatters() protected | yii\ | |
getDispositionHeaderValue() protected | Returns Content-Disposition header value that is safe to use with both old and new browsers. | yii\ |
getHttpRange() protected | Determines the HTTP range given in the request. | yii\ |
prepare() protected | Prepares for sending the response. | yii\ |
sendContent() protected | Sends the response content to the client. | yii\ |
sendCookies() protected | Sends the cookies to the client. | yii\ |
sendHeaders() protected | Sends the response headers to the client. | yii\ |
Events
Section titled “Events”| Event | Type | Description | Defined by |
|---|---|---|---|
EVENT_BEFORE_SEND | yii\ | An event that is triggered at the beginning of send(). Event name: 'beforeSend'. | yii\ |
EVENT_AFTER_SEND | yii\ | An event that is triggered at the end of send(). Event name: 'afterSend'. | yii\ |
EVENT_AFTER_PREPARE | yii\ | An event that is triggered right after prepare() is called in send(). Event name: 'afterPrepare'. | yii\ |
Constants
Section titled “Constants”| Constant | Value | Description | Defined by |
|---|---|---|---|
FORMAT_RAW | 'raw' | yii\ | |
FORMAT_HTML | 'html' | yii\ | |
FORMAT_JSON | 'json' | yii\ | |
FORMAT_JSONP | 'jsonp' | yii\ | |
FORMAT_XML | 'xml' | yii\ |
Property details
Section titled “Property details”$cookieValidationKey
Section titled “$cookieValidationKey ”public string $cookieValidationKey = ''A secret key used for cookie validation.
Set this property when $enableCookieValidation is true.
Method details
Section titled “Method details”captureSessionCookie()
Section titled “captureSessionCookie() ”public function captureSessionCookie(): voidQueues the current session ID, including rotation followed by an explicit close.
completeSend()
Section titled “completeSend() ”public function completeSend(): voidCompletes the Yii response send lifecycle after the runtime emits the PSR-7 body.
Triggers EVENT_AFTER_SEND and marks the response as sent, running the back half of send() that
getPsr7Response() intentionally defers. Returns immediately when the response is already sent.
Call this after the PSR-7 response has been emitted so lazy body streams (such as sendFile() or
sendStreamAsFile()) are consumed before after-send handlers run.
getPsr7Response()
Section titled “getPsr7Response() ”public function getPsr7Response(): Psr\Http\Message\ResponseInterfaceConverts the Yii Response component to a PSR-7 ResponseInterface instance.
Triggers before-send and after-prepare, closes an active session after queuing its cookie, and delegates
conversion to ResponseAdapter. Does not emit bytes, trigger after-send, or mark the response sent.
Use Application::finalize() after emission for application-managed responses; for standalone use,
call completeSend() after successful emission.
Returns
Psr\Http\Message\ResponseInterface: PSR-7 ResponseInterface instance representing the current Yii Response.
Throws
yii\base\InvalidConfigException: if the configuration is invalid or incomplete.yii\di\NotInstantiableException: if a class or service can’t be instantiated.