Index

Response

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

class

Response

Response.php:21

Psr Response with a body as an object.

class MMO\core\server\Response extends MMO\core\classes\aResponse implements JsonSerializable
Namespace
MMO\core\server
Extends
aResponse
Implements
JsonSerializable
The response is not renderable iself. Only its body. So it is possible to wrap the body in specific headers/footers
$r = Response::Json(['name' => 'bar']); $r->getContentType(); // 'application/json' $r->render(); // '{"meta":[],"links":[],"data":{"name":"bar"},"logs":[]}'

Index

document
Csv($document, $status, $reason, $headers) staticGenerate a Csv response with a plain Document (using CsvPrinter::Encode) as body
FromMime($mime, $document, $status, $reason, $headers) staticBuild a Response using the static factory matching a given mime type/extension (extension), passing $document through to it.
getBody()Gets the body of the message.
getParsedBody()Retrieve the response body.
Html($document, $status, $reason, $headers) staticGenerate an Html response with an HtmlDocument as body
Json($document, $status, $reason, $headers) staticGenerate a Json response with a JsonDocument as body
jsonSerialize()
lock()Mark the body document read-only (no further mutation allowed).
logEvent($event)
Redirect($redirectUri, $headers, $post, $status, $reason) static
render($opts)
Shell($document, $status, $reason, $headers) staticGenerate a Text response with a TextDocument as body, rendered via ShellPrinter (ANSI-colored output for terminals) instead of TextDocument's default plain-text printer.
Text($document, $status, $reason, $headers) staticGenerate a Text response with a TextDocument as body
withBody($body)Return an instance with the specified message body.
withParsedBody($data)
Xlsx($document, $status, $reason, $headers) staticGenerate an Xlsx (excel) response with a XlsxDocument as body
Xml($document, $status, $reason, $headers) staticGenerate an Xml response with an XmlDocument as body
__construct($document, $status, $reason, $headers)
__toString()

Properties1

document

MMO\core\documents\Document $document
Type
Document

Methods19

Csv($document, $status, $reason, $headers)

staticResponse.php:153

Generate a Csv response with a plain Document (using CsvPrinter::Encode) as body

static function Csv( MMO\core\documents\Document|array $document = [], int $status = 200, string $reason = '', array $headers = [] ): self
$document = []Document | arraya plain array (a flat list of records) or an already-built Document.
$status = 200intResponse status
$reason = ''stringStatus text
$headers = []arrayheaders
returnsself

FromMime($mime, $document, $status, $reason, $headers)

staticResponse.php:118

Build a Response using the static factory matching a given mime type/extension (extension), passing $document through to it.

static function FromMime( string $mime, MMO\core\documents\Document|array|null $document = null, int $status = 200, string $reason = '', array $headers = [] ): selfNOTE: 'xml'/'html' build their body from an XmlNodes tree ([`XmlDocument`](https://mmoframework.fr/documentation/mmo.core/php/documents/XmlDocument.md#xmldocument)/[`HtmlDocument`](https://mmoframework.fr/documentation/mmo.core/php/documents/HtmlDocument.md#htmldocument)), not from arbitrary data -- there is no defined mapping from a plain array to markup, so $document must be null or an already-built XmlDocument/HtmlDocument for those two mime types (a plain array throws [`eInvalid`](https://mmoframework.fr/documentation/mmo.core/php/exceptions/eInvalid.md#einvalid) instead of the confusing internal TypeError that used to surface from [`Xml`](https://mmoframework.fr/documentation/mmo.core/php/server/Response.md#response-xml)/[`Html`](https://mmoframework.fr/documentation/mmo.core/php/server/Response.md#response-html)'s own, stricter parameter types).
See
extension resolves it, and only matches full mime-type strings).
$mimestringa mime type header value, e.g. 'application/json' (NOT a bare extension like 'json' --
$document = nullDocument | array | nullthe body to use, appropriate to the resolved mime type (see NOTE above).
$status = 200int
$reason = ''string
$headers = []array
returnsself
throwsif $mime resolves to 'xml'/'html' and $document is a plain array.
Response::FromMime('application/json', ['a' => 1]); // a Json response

getBody()

Response.php:233

Gets the body of the message.

function getBody(): Psr\Http\Message\StreamInterface
returnsStreamInterfaceReturns the body as a stream.

getParsedBody()

Response.php:265

Retrieve the response body.

function getParsedBody(): MMO\core\documents\DocumentOtherwise, this method may return any results of deserializing the response body content; as parsing returns structured content, the potential types MUST be arrays or objects only. A null value indicates the absence of body content.
returnsDocumentThe deserialized body response, if any. These will typically be an array or object.

Html($document, $status, $reason, $headers)

staticResponse.php:193

Generate an Html response with an HtmlDocument as body

static function Html( ?MMO\core\documents\HtmlDocument $document = null, int $status = 200, string $reason = '', array $headers = [] ): self
$document = nullnull | HtmlDocument
$status = 200intResponse status
$reason = ''stringStatus text
$headers = []arrayheaders
returnsself

Json($document, $status, $reason, $headers)

staticResponse.php:139

Generate a Json response with a JsonDocument as body

static function Json( MMO\core\documents\JsonDocument|array $document = [], int $status = 200, string $reason = '', array $headers = [] ): self
$document = []JsonDocument | array
$status = 200intResponse status
$reason = ''stringStatus text
$headers = []arrayheaders
returnsself

jsonSerialize()

Response.php:52
function jsonSerialize(): mixed
returnsmixedthe body document (its own jsonSerialize() then does the actual encoding).

lock()

Response.php:66

Mark the body document read-only (no further mutation allowed).

function lock(): void
returnsvoid

Redirect($redirectUri, $headers, $post, $status, $reason)

staticResponse.php:83
static function Redirect( string $redirectUri, array $headers = [], ?array $post = null, int $status = 302, string $reason = '' ): self
$redirectUristringthe url to redirect to
$headers = []arraythe headers to use
$post = nullnull | arrayif not null, will submit a form instead of using header location
$status = 302intthe status
$reason = ''stringthe reason
returnsself

render($opts)

Response.php:61
function render(array $opts = []): string
See
iRenderable::render
$opts = []arrayforwarded to the document's own render().
returnsstringthe rendered document.

Shell($document, $status, $reason, $headers)

staticResponse.php:180

Generate a Text response with a TextDocument as body, rendered via ShellPrinter (ANSI-colored output for terminals) instead of TextDocument's default plain-text printer.

static function Shell( MMO\core\documents\TextDocument|array $document = [], int $status = 200, string $reason = '', array $headers = [] ): self
$document = []TextDocument | array
$status = 200intResponse status
$reason = ''stringStatus text
$headers = []arrayheaders
returnsself

Text($document, $status, $reason, $headers)

staticResponse.php:166

Generate a Text response with a TextDocument as body

static function Text( MMO\core\documents\TextDocument|array $document = [], int $status = 200, string $reason = '', array $headers = [] ): self
$document = []TextDocument | array
$status = 200intResponse status
$reason = ''stringStatus text
$headers = []arrayheaders
returnsself

withBody($body)

Response.php:250

Return an instance with the specified message body.

function withBody(Psr\Http\Message\StreamInterface $body): Psr\Http\Message\ResponseInterfaceThe body MUST be a StreamInterface object. This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return a new instance that has the new body stream.
$bodyStreamInterfaceBody.
returnsResponseInterface
throwsWhen the body is not valid.

withParsedBody($data)

Response.php:274
function withParsedBody(ArrayAccess|array|null $data): self
$dataArrayAccess | array | nullreplaces the response's document -- a plain array/\ArrayAccess is wrapped in a plain Document (losing whatever printer/type the previous document had).
returnsselfa clone with the new document.

Xlsx($document, $status, $reason, $headers)

staticResponse.php:219

Generate an Xlsx (excel) response with a XlsxDocument as body

static function Xlsx( ?MMO\core\documents\xlsx\Document $document = null, int $status = 200, string $reason = '', array $headers = [] ): self
$document = nullnull | Document
$status = 200intResponse status
$reason = ''stringStatus text
$headers = []arrayheaders
returnsself

Xml($document, $status, $reason, $headers)

staticResponse.php:206

Generate an Xml response with an XmlDocument as body

static function Xml( ?MMO\core\documents\XmlDocument $document = null, int $status = 200, string $reason = '', array $headers = [] ): self
$document = nullnull | XmlDocument
$status = 200intResponse status
$reason = ''stringStatus text
$headers = []arrayheaders
returnsself

__construct($document, $status, $reason, $headers)

Response.php:34
function __construct( ArrayAccess|array|null $document = null, int $status = 200, string $reason = '', array $headers = [] )
$document = nullArrayAccess | array | nullthe parsed body of the response -- a plain array/\ArrayAccess is wrapped in a plain Document; pass an already-built Document (e.g. from Json/Html/...) to control its type/printer instead.
$status = 200intResponse status
$reason = ''stringStatus text
$headers = []arrayheaders
Inherited members (62)
PropertiesDeclared byDescription
headersaMessage
ikeysaMessage
ListenersaMessage
protocolaMessage
statusCodeaResponse
statusTextaResponse
stoppedaResponse
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.
debugName()aResponse
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.
getCharset()aMessage
getContentExtension()aMessage
getContentType($single)aMessage
getExitCode()aResponse
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.
getProtocolVersion()aMessageRetrieves the HTTP protocol version as a string.
getReasonPhrase()aResponseGets the response reason phrase associated with the status code.
getRedirect()aResponse
getStatusCode()aResponseGets the response status code.
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
isOk()aResponse
isPropagationStopped()aResponse
isWindows()aMessage
RemoveListener($handler)aMessageRemove the last added handler from the listeners.
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).
setRedirect($url, $status)aResponseSet a redirection call send() to actually redirect
setRequireAuth($realm, $type)aResponseSet redirection to a login/password inputbox call send() to actually redirect
setStatus($code, $reason)aResponse
stopPropagation()aResponsePrevent any remaining listener in the current dispatch chain from being called.
unsetHeader($name)aMessageRemove a header entirely.
withAddedHeader($name, $value)aMessageReturn an instance with the specified header appended with the given value.
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.
withProtocolVersion($version)aMessageReturn an instance with the specified HTTP protocol version.
withRedirect($url, $status)aResponseSet a redirection of a clone call send() to actually redirect
withRequireAuth($realm, $type)aResponseSet redirection to a login/password inputbox of a clone call send() to actually redirect
withStatus($code, $reasonPhrase)aResponseReturn an instance with the specified status code and, optionally, reason phrase.
__clone()aResponseA cloned event starts fresh: propagation is never considered stopped on the clone, even if it was on the original instance.