Skip to content
PHP Ecosystem
Explore

Response

API reference › PSR bridge › http › Response

classyii2\extensions\psrbridge\http\Response
Extendsyii\web\Response » yii\base\Response » yii\base\Component » yii\base\BaseObject
Implementsyii\base\Configurable
Sourcesrc/http/Response.php

Extends Yii response handling with PSR-7 response conversion.

ResponseAdapter Yii response to PSR-7 response adapter.

PropertyTypeDescriptionDefined by
$acceptMimeTypestring|nullThe MIME type (e.g. application/json) from the request ACCEPT header chosen for this response. Default: null.yii\web\Response
$acceptParamsarrayThe parameters (e.g. ['q' => 1, 'version' => '1.0']) associated with the chosen MIME type. Default: [].yii\web\Response
$behaviors read-onlyarray<yii\base\Behavior<static>>List of behaviors attached to this component.yii\base\Component
$charsetstring|nullThe charset of the text response. Default: null.yii\web\Response
$contentstring|nullThe response content. Default: null.yii\web\Response
$cookies read-onlyyii\web\CookieCollectionThe cookie collection.yii\web\Response
$cookieValidationKeystringA secret key used for cookie validation. Default: ''.Response
$datamixedThe original response data. Default: null.yii\web\Response
$downloadHeaders write-onlystringThe attachment file name.yii\web\Response
$enableCookieValidationboolWhether to sign outgoing cookie values with $cookieValidationKey. Default: false.Response
$exitStatusintThe exit status. Default: 0.yii\base\Response
$formatstringThe response format. Default: self::FORMAT_HTML.yii\web\Response
$formattersarrayThe formatters for converting data into the response content of the specified $format. Default: [].yii\web\Response
$headers read-onlyyii\web\HeaderCollectionThe header collection.yii\web\Response
$httpStatuses staticarrayList of HTTP status codes and the corresponding texts Default: [100 => 'Continue', 101 => 'Switching Protocols', 102 => 'Processing', 118 => 'Connection timed out', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-Status', 208 => 'Already Reported', 210 => 'Content Different', 226 => 'IM Used', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 306 => 'Reserved', 307 => 'Temporary Redirect', 308 => 'Permanent Redirect', 310 => 'Too many Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested range unsatisfiable', 417 => 'Expectation failed', 418 => 'I\'m a teapot', 421 => 'Misdirected Request', 422 => 'Unprocessable entity', 423 => 'Locked', 424 => 'Method failure', 425 => 'Unordered Collection', 426 => 'Upgrade Required', 428 => 'Precondition Required', 429 => 'Too Many Requests', 431 => 'Request Header Fields Too Large', 449 => 'Retry With', 450 => 'Blocked by Windows Parental Controls', 451 => 'Unavailable For Legal Reasons', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway or Proxy Error', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported', 507 => 'Insufficient storage', 508 => 'Loop Detected', 509 => 'Bandwidth Limit Exceeded', 510 => 'Not Extended', 511 => 'Network Authentication Required'].yii\web\Response
$isClientError read-onlyboolWhether this response indicates a client error.yii\web\Response
$isEmpty read-onlyboolWhether this response is empty.yii\web\Response
$isForbidden read-onlyboolWhether this response indicates the current request is forbidden.yii\web\Response
$isInformational read-onlyboolWhether this response is informational.yii\web\Response
$isInvalid read-onlyboolWhether this response has a valid $statusCode.yii\web\Response
$isNotFound read-onlyboolWhether this response indicates the currently requested resource is not found.yii\web\Response
$isOk read-onlyboolWhether this response is OK.yii\web\Response
$isRedirection read-onlyboolWhether this response is a redirection.yii\web\Response
$isSentboolWhether the response has been sent. Default: false.yii\web\Response
$isServerError read-onlyboolWhether this response indicates a server error.yii\web\Response
$isSuccessful read-onlyboolWhether this response is successful.yii\web\Response
$psr7Response read-onlyPsr\Http\Message\ResponseInterfacePSR-7 ResponseInterface instance representing the current Yii Response.Response
$statusCodeintThe HTTP status code to send with the response.yii\web\Response
$statusCodeByException write-onlyThrowableThe exception object.yii\web\Response
$statusTextstringThe HTTP status description that comes together with the status code. Default: 'OK'.yii\web\Response
$streamresource|array|callable|nullThe stream to be sent. Default: null.yii\web\Response
$versionstring|nullThe version of the HTTP protocol to use. Default: null.yii\web\Response
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.yii\base\Component
__clone()This method is called after the object is created by cloning an existing one.yii\base\Component
__get()Returns the value of a component property.yii\base\Component
__isset()Checks if a property is set, i.e. defined and not null.yii\base\Component
__set()Sets the value of a component property.yii\base\Component
__unset()Sets a component property to be null.yii\base\Component
attachBehavior()Attaches a behavior to this component.yii\base\Component
attachBehaviors()Attaches a list of behaviors to the component.yii\base\Component
behaviors()Returns a list of behaviors that this component should behave as.yii\base\Component
canGetProperty()Returns a value indicating whether a property can be read.yii\base\Component
canSetProperty()Returns a value indicating whether a property can be set.yii\base\Component
captureSessionCookie()Queues the current session ID, including rotation followed by an explicit close.Response
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
clear()Clears the headers, cookies, content, status code of the response.yii\web\Response
clearOutputBuffers()Removes all existing output buffers.yii\base\Response
completeSend()Completes the Yii response send lifecycle after the runtime emits the PSR-7 body.Response
detachBehavior()Detaches a behavior from the component.yii\base\Component
detachBehaviors()Detaches all behaviors from the component.yii\base\Component
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.yii\base\Component
getBehavior()Returns the named behavior object.yii\base\Component
getBehaviors()Returns all behaviors attached to this component.yii\base\Component
getCookies()Returns the cookie collection.yii\web\Response
getHeaders()Returns the header collection.yii\web\Response
getIsClientError()yii\web\Response
getIsEmpty()yii\web\Response
getIsForbidden()yii\web\Response
getIsInformational()yii\web\Response
getIsInvalid()yii\web\Response
getIsNotFound()yii\web\Response
getIsOk()yii\web\Response
getIsRedirection()yii\web\Response
getIsServerError()yii\web\Response
getIsSuccessful()yii\web\Response
getPsr7Response()Converts the Yii Response component to a PSR-7 ResponseInterface instance.Response
getStatusCode()yii\web\Response
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.yii\base\Component
hasMethod()Returns a value indicating whether a method is defined.yii\base\Component
hasProperty()Returns a value indicating whether a property is defined for this component.yii\base\Component
init()Initializes this component.yii\web\Response
off()Detaches an existing event handler from this component.yii\base\Component
on()Attaches an event handler to an event.yii\base\Component
redirect()Redirects the browser to the specified URL.yii\web\Response
refresh()Refreshes the current page.yii\web\Response
send()Sends the response to the client.yii\web\Response
sendContentAsFile()Sends the specified content as a file to the browser.yii\web\Response
sendFile()Sends a file to the browser.yii\web\Response
sendStreamAsFile()Sends the specified stream as a file to the browser.yii\web\Response
setDownloadHeaders()Sets a default set of HTTP headers for file downloading purpose.yii\web\Response
setStatusCode()Sets the response status code.yii\web\Response
setStatusCodeByException()Sets the response status code based on the exception.yii\web\Response
trigger()Triggers an event.yii\base\Component
xSendFile()Sends existing file to a browser as a download using x-sendfile.yii\web\Response
defaultFormatters() protectedyii\web\Response
getDispositionHeaderValue() protectedReturns Content-Disposition header value that is safe to use with both old and new browsers.yii\web\Response
getHttpRange() protectedDetermines the HTTP range given in the request.yii\web\Response
prepare() protectedPrepares for sending the response.yii\web\Response
sendContent() protectedSends the response content to the client.yii\web\Response
sendCookies() protectedSends the cookies to the client.yii\web\Response
sendHeaders() protectedSends the response headers to the client.yii\web\Response
EventTypeDescriptionDefined by
EVENT_BEFORE_SENDyii\base\EventAn event that is triggered at the beginning of send(). Event name: 'beforeSend'.yii\web\Response
EVENT_AFTER_SENDyii\base\EventAn event that is triggered at the end of send(). Event name: 'afterSend'.yii\web\Response
EVENT_AFTER_PREPAREyii\base\EventAn event that is triggered right after prepare() is called in send(). Event name: 'afterPrepare'.yii\web\Response
public string $cookieValidationKey = ''

A secret key used for cookie validation.

Set this property when $enableCookieValidation is true.

public function captureSessionCookie(): void

Queues the current session ID, including rotation followed by an explicit close.

public function completeSend(): void

Completes 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.

public function getPsr7Response(): Psr\Http\Message\ResponseInterface

Converts 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