Index

aResponse

MMO\core\classes · 1 symbol · generated 30 Sep 2026

class

aResponse

aResponse.php:16

Base implementation of PSR-7's ResponseInterface (Response extends this): status code/reason phrase, plus convenience helpers for common response shapes (redirects, HTTP auth challenges).

abstract class MMO\core\classes\aResponse extends MMO\core\classes\aMessage implements MMO\core\interfaces\iResponse use MMO\core\classes\tStoppableEvent
Namespace
MMO\core\classes
Extends
aMessage
Implements
iResponse
Uses traits
tStoppableEvent
Immutable like [`aMessage`](https://mmoframework.fr/documentation/mmo.core/php/classes/aMessage.md#amessage): every `with*()` method returns a clone. A concrete subclass is expected to implement `render(array $opts = []): string` (used by [`__toString`](https://mmoframework.fr/documentation/mmo.core/php/classes/aResponse.md#aresponse--tostring)) to turn the response into its final body.
$r = new Response(); // 200 OK by default $r2 = $r->withStatus(404); // $r2 !== $r; $r is still 200 $r3 = $r->withRedirect('/login', 303);

Index

statusCode
statusText
stopped
debugName()
getExitCode()
getReasonPhrase()Gets the response reason phrase associated with the status code.
getRedirect()
getStatusCode()Gets the response status code.
isOk()
isPropagationStopped()
setRedirect($url, $status)Set a redirection call send() to actually redirect
setRequireAuth($realm, $type)Set redirection to a login/password inputbox call send() to actually redirect
setStatus($code, $reason)
stopPropagation()Prevent any remaining listener in the current dispatch chain from being called.
withRedirect($url, $status)Set a redirection of a clone call send() to actually redirect
withRequireAuth($realm, $type)Set redirection to a login/password inputbox of a clone call send() to actually redirect
withStatus($code, $reasonPhrase)Return an instance with the specified status code and, optionally, reason phrase.
__clone()A cloned event starts fresh: propagation is never considered stopped on the clone, even if it was on the original instance.
__construct($code, $reason, $headers)
__toString()

Properties3

statusCode

protected int $statusCode
Type
int

statusText

protected string $statusText
Type
string

stopped

protected $stopped = false

Methods17

getExitCode()

aResponse.php:59
function getExitCode(): int
returnsintthe CLI process exit code conventionally associated with this response's status code (e.g. for a shell command's response)

getReasonPhrase()

aResponse.php:181

Gets the response reason phrase associated with the status code.

function getReasonPhrase(): stringBecause a reason phrase is not a required element in a response status line, the reason phrase value MAY be null. Implementations MAY choose to return the default RFC 7231 recommended reason phrase (or those listed in the IANA HTTP Status Code Registry) for the response's status code.
returnsstringReason phrase; must return an empty string if none present.
$response->getReasonPhrase(); // 'OK', or 'Not Found' for a 404, etc.

getRedirect()

aResponse.php:72
function getRedirect(): ?string
returnsnull | stringthe Location header's value, or null if this response has no redirect set
$response->withRedirect('/login')->getRedirect(); // '/login'

getStatusCode()

aResponse.php:136

Gets the response status code.

function getStatusCode(): intThe status code is a 3-digit integer result code of the server's attempt to understand and satisfy the request.
returnsintStatus code.
$response->getStatusCode(); // 200

isOk()

aResponse.php:64
function isOk(): bool
returnsbooltrue if the status code represents success (2xx)

setRedirect($url, $status)

aResponse.php:84

Set a redirection call send() to actually redirect

protected function setRedirect($url, $status = 302): self
$urlthe url to redirect to
$status = 302status code
returnsself$this, for chaining

setRequireAuth($realm, $type)

aResponse.php:108

Set redirection to a login/password inputbox call send() to actually redirect

protected function setRequireAuth(string $realm, string $type = 'Digest'): self
$realmstringrandom string
$type = 'Digest'stringthe WWW-Authenticate scheme, e.g. 'Digest' (default) or 'Basic'
returnsself

stopPropagation()

tStoppableEvent.php:29

Prevent any remaining listener in the current dispatch chain from being called.

function stopPropagation()
returns

withRedirect($url, $status)

aResponse.php:97

Set a redirection of a clone call send() to actually redirect

function withRedirect(string $url, int $status = 302): self
$urlstringthe url to redirect to
$status = 302intstatus code
returnsself
$response->withRedirect('/login'); // status 302, Location: /login$response->withRedirect('/login', 303);

withRequireAuth($realm, $type)

aResponse.php:121

Set redirection to a login/password inputbox of a clone call send() to actually redirect

function withRequireAuth(string $realm, string $type = 'Digest'): self
$realmstringrandom string
$type = 'Digest'stringthe WWW-Authenticate scheme, e.g. 'Digest' (default) or 'Basic'
returnsself
$response->withRequireAuth('my-app'); // status 401, with a Digest WWW-Authenticate challenge

withStatus($code, $reasonPhrase)

aResponse.php:162

Return an instance with the specified status code and, optionally, reason phrase.

function withStatus(int $code, string $reasonPhrase = ''): selfIf no reason phrase is specified, implementations MAY choose to default to the RFC 7231 or IANA recommended reason phrase for the response's status code. This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that has the updated status and reason phrase.
$codeintThe 3-digit integer result code to set.
$reasonPhrase = ''stringThe reason phrase to use with the provided status code; if none is provided, implementations MAY use the defaults as suggested in the HTTP specification.
returnsself
throwsFor invalid status code arguments.
$response->withStatus(404);$response->withStatus(200, 'Custom OK');

__clone()

tStoppableEvent.php:38

A cloned event starts fresh: propagation is never considered stopped on the clone, even if it was on the original instance.

function __clone()
returns

__construct($code, $reason, $headers)

aResponse.php:27
function __construct(int $code = 200, string $reason = '', array $headers = [])
$code = 200intResponse code
$reason = ''stringStatus text -- if empty, defaults to the standard reason for $code (statusMessage)
$headers = []arrayheaders

__toString()

aResponse.php:33
function __toString(): string
returnsstringthe rendered response body, via the subclass's own render() implementation
Inherited members (51)
PropertiesDeclared byDescription
headersaMessage
ikeysaMessage
ListenersaMessage
protocolaMessage
MethodsDeclared byDescription
addHeader($name, $value)aMessageAppend a value to a header, keeping any value(s) already set (as opposed to setHeader, which replaces).
AddListener($handler, $order)aMessageRegister a listener directly (as opposed to ConnectListeners's attribute-based discovery).
ConnectListeners($obj)aMessageScan $obj's methods for #[Listen(EventClass::class)] attributes and register each one as a listener on the matching event class.
DisconnectListeners($obj)aMessageUndo a previous ConnectListeners: removes every listener that connect had registered for $obj on this event class.
dispatch()aMessageInvoke every GetListeners listener with $this.
getBody()MessageInterfaceGets the body of the message.
getCharset()aMessage
getContentExtension()aMessage
getContentType($single)aMessage
getHeader($name)aMessageRetrieves a message header value by the given case-insensitive name.
getHeaderLine($name)aMessageRetrieves a comma-separated string of the values for a single header.
getHeaders()aMessageRetrieves all message header values.
GetListeners()aMessageCollect every listener for this class, including those registered on its parent classes (so a subclass event is also caught by listeners of its parent event), sorted by ascending $order (ties keep …
getOrigin()aMessageGet origin of the request by looking at 'Origin', then 'Referer', then 'Sender' in the request's headers.
getParsedBody()aMessage
getProtocolVersion()aMessageRetrieves the HTTP protocol version as a string.
getUserAgent()aMessage
hasHeader($name)aMessageChecks if a header exists by the given case-insensitive name.
HasListener($handler)aMessage
isHTML()aMessage
isIe()aMessage
isIphone()aMessage
isJSON()aMessage
isMac()aMessage
isMobile()aMessage
isWindows()aMessage
lock()iResponse
logEvent($event)iResponse
RemoveListener($handler)aMessageRemove the last added handler from the listeners.
render($opts)iRenderable
Send($args)aMessageConstruct a new instance of this class with $args, then dispatch it to every listener.
setCacheControl($cache, $pragma)aMessageSet the Cache-Control header (and, optionally, the legacy Pragma header alongside it).
setContentType($type, $charset)aMessageSet the Content-Type header, appending a charset parameter (unless $charset is null/empty).
setExpires($time)aMessageSet the Expires header from a unix timestamp, formatted as an RFC 7231 HTTP-date.
setHeader($name, $value)aMessageSet header, replacing any previous value(s) for the same (case-insensitively matched) header name.
SetListenerOrder($handler, $order)aMessageChange the order of an already-registered listener, whether added directly via AddListener or indirectly via ConnectListeners (which also stores its [$obj, $methodName] callables here).
unsetHeader($name)aMessageRemove a header entirely.
withAddedHeader($name, $value)aMessageReturn an instance with the specified header appended with the given value.
withBody($body)MessageInterfaceReturn an instance with the specified message body.
withCacheControl($cache, $pragma)aMessageSet cache control of a clone.
withContentType($type, $charset)aMessageSet content type of a clone.
withExpires($time)aMessageSet cache expire date of a clone.
withHeader($name, $value)aMessageReturn an instance with the provided value replacing the specified header.
withHeaders($headers, $reset)aMessageReturn a clone with every header in $headers set (through tWithHeaders::setHeader, so each value replaces any existing one for the same header name).
withoutHeader($name)aMessageReturn an instance without the specified header.
withParsedBody($data)aMessage
withProtocolVersion($version)aMessageReturn an instance with the specified HTTP protocol version.