Mage_Core_Controller_Response_Http
in package
implements
Stringable
HTTP Response class wrapping Symfony Response
Provides compatibility layer for Mage_Core_Controller_Response_Http while using Symfony HttpFoundation
Table of Contents
Interfaces
- Stringable
Properties
- $headersSentThrowsException : bool
- Exception thrown by action controller
- $_body : array<string|int, mixed>
- Body content
- $_bodyOrder : array<string|int, mixed>
- Body segment order
- $_exceptions : array<string|int, mixed>
- Array of exceptions
- $_headersRaw : array<string|int, mixed>
- Array of raw headers
- $_headersSent : bool
- Whether headers have been emitted; Symfony sends with replace=false, so a second emission would duplicate headers instead of replacing them
- $_isRedirect : bool
- Flag; is this response a redirect?
- $_outputCallback : mixed
- Output callback
- $_transportObject : DataObject|null
- Transport object for observers to perform
- $symfonyResponse : Response
- Symfony Response instance
Methods
- __construct() : mixed
- __toString() : string
- Magic __toString functionality
- append() : self
- Append content to a body segment
- appendBody() : self
- Append content to the body content
- canSendHeaders() : bool
- Can we send headers?
- clearAllHeaders() : self
- Clear all headers, normal and raw
- clearBody() : self
- Clear body content
- clearCookie() : self
- Clear cookie (set with past expiry)
- clearHeader() : self
- Clear header by name
- clearHeaders() : self
- Clear headers
- clearRawHeader() : self
- Clear a specific raw header
- clearRawHeaders() : self
- Clear all raw headers
- finishRequest() : void
- Hand the response back to the client and release the session lock.
- getBody() : string|array<string|int, mixed>
- Return the body content
- getException() : array<string|int, mixed>
- Retrieve the exception stack
- getExceptionByCode() : false|Throwable
- Retrieve first exception with a given code
- getExceptionByMessage() : false|Throwable
- Retrieve first exception with a given message
- getExceptionByType() : false|Throwable
- Retrieve first exception of given type
- getExceptions() : array<string|int, mixed>
- Retrieve the exception stack (alias)
- getHeaders() : array<string|int, mixed>
- Return headers as [['name' => ..., 'value' => ..., 'replace' => ...], ...] (legacy M1 format, derived from the Symfony header bag)
- getHttpResponseCode() : int
- Retrieve HTTP response code
- getOutputCallback() : mixed
- Get output callback
- getRawHeaders() : array<string|int, mixed>
- Get all header values as an array
- getSymfonyResponse() : Response
- Get the Symfony Response instance (for internal use)
- hasExceptionOfCode() : bool
- Does the response object contain an exception with a given code?
- hasExceptionOfMessage() : bool
- Does the response object contain an exception with a given message?
- hasExceptionOfType() : bool
- Does the response object contain an exception of a given type?
- hasExceptions() : bool
- Has an exception been registered with the response? (alias for isException)
- hasHeader() : bool
- Whether a header is present
- insert() : self
- Insert content before a named segment
- isException() : bool
- Has an exception been registered with the response?
- isRedirect() : bool
- Is this a redirect?
- isSent() : bool
- Check if response has been sent
- outputBody() : string
- Echo the body segments
- prepend() : self
- Prepend content to a body segment
- prependBody() : self
- Prepend content to body
- sendHeaders() : self
- Send all headers
- sendHeadersAndExit() : never
- Method send already collected headers and exit from script
- sendJsonAndDetach() : void
- Send a JSON payload, close the connection, and keep executing in the background.
- sendResponse() : void
- Send the response, including all headers
- setBody() : self
- Set body content
- setBodyJson() : self
- Prepare JSON formatted data for response to client
- setCookie() : self
- Set cookie
- setException() : self
- Register an exception with the response
- setHeader() : self
- Set a header
- setHttpResponseCode() : self
- Set HTTP response code to use with headers
- setOutputCallback() : self
- Set output callback
- setOutputOrder() : self
- Set body segment output order
- setRawHeader() : self
- Set raw HTTP header
- setRedirect() : self
- Set redirect URL
- setRedirectUrl() : self
- Set redirect URL without exit
- _normalizeHeader() : string
- Normalize a header name
- deferJavaScriptLoading() : string
- Defer JavaScript loading based on selected mode
- getJavaScriptDeferMode() : int
- getJavaScriptLoader() : string
- isJavaScriptTag() : bool
- Tell if a <script> tag holds code the browser executes, so it can be deferred
- shouldDeferJavaScript() : bool
- Check if JavaScript deferral should be applied
Properties
$headersSentThrowsException
Exception thrown by action controller
public
bool
$headersSentThrowsException
= \false
$_body
Body content
protected
array<string|int, mixed>
$_body
= []
$_bodyOrder
Body segment order
protected
array<string|int, mixed>
$_bodyOrder
= []
$_exceptions
Array of exceptions
protected
array<string|int, mixed>
$_exceptions
= []
$_headersRaw
Array of raw headers
protected
array<string|int, mixed>
$_headersRaw
= []
$_headersSent
Whether headers have been emitted; Symfony sends with replace=false, so a second emission would duplicate headers instead of replacing them
protected
bool
$_headersSent
= \false
$_isRedirect
Flag; is this response a redirect?
protected
bool
$_isRedirect
= \false
$_outputCallback
Output callback
protected
mixed
$_outputCallback
= \null
$_transportObject
Transport object for observers to perform
protected
static DataObject|null
$_transportObject
= \null
$symfonyResponse
Symfony Response instance
protected
Response
$symfonyResponse
Methods
__construct()
public
__construct([array<string|int, mixed>|Response|null $args = null ]) : mixed
Parameters
- $args : array<string|int, mixed>|Response|null = null
__toString()
Magic __toString functionality
public
__toString() : string
Attributes
- #[Override]
Return values
stringappend()
Append content to a body segment
public
append(string $name, string $content) : self
Parameters
- $name : string
- $content : string
Return values
selfappendBody()
Append content to the body content
public
appendBody(string $content[, string|null $name = null ]) : self
Parameters
- $content : string
- $name : string|null = null
Return values
selfcanSendHeaders()
Can we send headers?
public
canSendHeaders([bool $throw = false ]) : bool
Parameters
- $throw : bool = false
Return values
boolclearAllHeaders()
Clear all headers, normal and raw
public
clearAllHeaders() : self
Return values
selfclearBody()
Clear body content
public
clearBody([string|null $name = null ]) : self
Parameters
- $name : string|null = null
Return values
selfclearCookie()
Clear cookie (set with past expiry)
public
clearCookie(string $name[, string $path = '/' ][, string|null $domain = null ]) : self
Parameters
- $name : string
- $path : string = '/'
- $domain : string|null = null
Return values
selfclearHeader()
Clear header by name
public
clearHeader(string $name) : self
Parameters
- $name : string
Return values
selfclearHeaders()
Clear headers
public
clearHeaders() : self
Return values
selfclearRawHeader()
Clear a specific raw header
public
clearRawHeader(string $headerRaw) : self
Parameters
- $headerRaw : string
Return values
selfclearRawHeaders()
Clear all raw headers
public
clearRawHeaders() : self
Return values
selffinishRequest()
Hand the response back to the client and release the session lock.
public
static finishRequest() : void
No output is allowed beyond this point. Whatever the script does next runs with the connection already closed, so concurrent requests from the same session no longer block.
getBody()
Return the body content
public
getBody([bool|string $spec = false ]) : string|array<string|int, mixed>
Parameters
- $spec : bool|string = false
Return values
string|array<string|int, mixed>getException()
Retrieve the exception stack
public
getException() : array<string|int, mixed>
Return values
array<string|int, mixed>getExceptionByCode()
Retrieve first exception with a given code
public
getExceptionByCode(int $code) : false|Throwable
Parameters
- $code : int
Return values
false|ThrowablegetExceptionByMessage()
Retrieve first exception with a given message
public
getExceptionByMessage(string $message) : false|Throwable
Parameters
- $message : string
Return values
false|ThrowablegetExceptionByType()
Retrieve first exception of given type
public
getExceptionByType(string $type) : false|Throwable
Parameters
- $type : string
Return values
false|ThrowablegetExceptions()
Retrieve the exception stack (alias)
public
getExceptions() : array<string|int, mixed>
Return values
array<string|int, mixed>getHeaders()
Return headers as [['name' => ..., 'value' => ..., 'replace' => ...], ...] (legacy M1 format, derived from the Symfony header bag)
public
getHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>getHttpResponseCode()
Retrieve HTTP response code
public
getHttpResponseCode() : int
Return values
intgetOutputCallback()
Get output callback
public
getOutputCallback() : mixed
getRawHeaders()
Get all header values as an array
public
getRawHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>getSymfonyResponse()
Get the Symfony Response instance (for internal use)
public
getSymfonyResponse() : Response
Return values
ResponsehasExceptionOfCode()
Does the response object contain an exception with a given code?
public
hasExceptionOfCode(int $code) : bool
Parameters
- $code : int
Return values
boolhasExceptionOfMessage()
Does the response object contain an exception with a given message?
public
hasExceptionOfMessage(string $message) : bool
Parameters
- $message : string
Return values
boolhasExceptionOfType()
Does the response object contain an exception of a given type?
public
hasExceptionOfType(string $type) : bool
Parameters
- $type : string
Return values
boolhasExceptions()
Has an exception been registered with the response? (alias for isException)
public
hasExceptions() : bool
Return values
boolhasHeader()
Whether a header is present
public
hasHeader(string $name) : bool
Parameters
- $name : string
Return values
boolinsert()
Insert content before a named segment
public
insert(string $name, string $content[, string|null $parent = null ][, bool $before = false ]) : self
Parameters
- $name : string
- $content : string
- $parent : string|null = null
- $before : bool = false
Return values
selfisException()
Has an exception been registered with the response?
public
isException() : bool
Return values
boolisRedirect()
Is this a redirect?
public
isRedirect() : bool
Return values
boolisSent()
Check if response has been sent
public
isSent() : bool
Return values
booloutputBody()
Echo the body segments
public
outputBody() : string
Return values
stringprepend()
Prepend content to a body segment
public
prepend(string $name, string $content) : self
Parameters
- $name : string
- $content : string
Return values
selfprependBody()
Prepend content to body
public
prependBody(string $content[, string|null $name = null ]) : self
Parameters
- $content : string
- $name : string|null = null
Return values
selfsendHeaders()
Send all headers
public
sendHeaders() : self
Emission is delegated to the wrapped Symfony response, so ResponseHeaderBag defaults (conservative Cache-Control, Date) apply. The response is prepared against the current request first (RFC compliance: Content-Type charset, HEAD/304 body stripping, protocol version, secure cookies). Raw headers are sent after preparation and suppress any same-named header from the bag.
Return values
selfsendHeadersAndExit()
Method send already collected headers and exit from script
public
sendHeadersAndExit() : never
Return values
neversendJsonAndDetach()
Send a JSON payload, close the connection, and keep executing in the background.
public
sendJsonAndDetach(mixed $data) : void
Lets an action hand the client a handle (a token, an id) for a job that takes far longer than any request timeout allows. The caller must not emit anything afterwards; exit() once the work is done unless the rest of App::run() still has to happen.
Parameters
- $data : mixed
sendResponse()
Send the response, including all headers
public
sendResponse() : void
setBody()
Set body content
public
setBody(string $content[, string|null $name = null ]) : self
Parameters
- $content : string
- $name : string|null = null
Return values
selfsetBodyJson()
Prepare JSON formatted data for response to client
public
setBodyJson(mixed $response) : self
Parameters
- $response : mixed
Return values
selfsetCookie()
Set cookie
public
setCookie(string $name[, string $value = '' ][, int $lifetime = 0 ][, string $path = '/' ][, string|null $domain = null ][, bool $secure = false ][, bool $httponly = false ]) : self
Parameters
- $name : string
- $value : string = ''
- $lifetime : int = 0
- $path : string = '/'
- $domain : string|null = null
- $secure : bool = false
- $httponly : bool = false
Return values
selfsetException()
Register an exception with the response
public
setException(Throwable $e) : self
Parameters
- $e : Throwable
Return values
selfsetHeader()
Set a header
public
setHeader(string $name, string $value[, bool $replace = true ]) : self
Parameters
- $name : string
- $value : string
- $replace : bool = true
Return values
selfsetHttpResponseCode()
Set HTTP response code to use with headers
public
setHttpResponseCode(int $code) : self
Parameters
- $code : int
Return values
selfsetOutputCallback()
Set output callback
public
setOutputCallback(mixed $callback) : self
Parameters
- $callback : mixed
Return values
selfsetOutputOrder()
Set body segment output order
public
setOutputOrder(array<string|int, mixed> $order) : self
Parameters
- $order : array<string|int, mixed>
Return values
selfsetRawHeader()
Set raw HTTP header
public
setRawHeader(string $value) : self
Parameters
- $value : string
Return values
selfsetRedirect()
Set redirect URL
public
setRedirect(string $url[, int $code = 302 ]) : self
Sets Location header and response code. Forces replacement of any prior redirects.
Parameters
- $url : string
- $code : int = 302
Return values
selfsetRedirectUrl()
Set redirect URL without exit
public
setRedirectUrl(string $url) : self
Parameters
- $url : string
Return values
self_normalizeHeader()
Normalize a header name
protected
_normalizeHeader(string $name) : string
Parameters
- $name : string
Return values
stringdeferJavaScriptLoading()
Defer JavaScript loading based on selected mode
protected
deferJavaScriptLoading(string $html, int $mode) : string
Parameters
- $html : string
- $mode : int
Return values
stringgetJavaScriptDeferMode()
protected
getJavaScriptDeferMode() : int
Return values
intgetJavaScriptLoader()
protected
getJavaScriptLoader() : string
Return values
stringisJavaScriptTag()
Tell if a <script> tag holds code the browser executes, so it can be deferred
protected
isJavaScriptTag(string $tag) : bool
Parameters
- $tag : string
Return values
boolshouldDeferJavaScript()
Check if JavaScript deferral should be applied
protected
shouldDeferJavaScript(string $body) : bool
Parameters
- $body : string