Index

aRequest

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

class

aRequest

aRequest.php:19

Base implementation of PSR-7's (Server)RequestInterface (Request /

abstract class MMO\core\classes\aRequest extends MMO\core\classes\aMessage implements MMO\core\interfaces\iRequest, JsonSerializable, Stringable
Namespace
MMO\core\classes
Extends
aMessage
Implements
iRequest, JsonSerializable, Stringable
See
ShellRequest extend this) -- generic enough to represent an HTTP request or a CLI invocation ("request" in the framework's routing sense, either way). Immutable like aMessage: every with*() method returns a clone, leaving the original untouched.
$req = new Request('GET', 'https://example.com/foo'); $req2 = $req->withUri(Uri::Immutable('https://other.com/bar')); // $req2 !== $req; Host header synced to 'other.com'

Index

attributes
body
target
uri
debugName()
getAttribute($name, $default)Retrieve a single derived request attribute.
getAttributes()Retrieve attributes derived from the request.
getHeader($name)
getParsedBody()Retrieve any parameters provided in the request body.
getRequestTarget()Retrieves the message's request target.
getServerParams()Retrieve server parameters.
getUri($mutable)Retrieves the URI instance.
hasHeader($name)
HeaderName($name) staticThe name of the header php's $_SERVER calls $name -- the way a web server hands php a request's headers: HTTP_X_CSRF_TOKEN is X-Csrf-Token, CONTENT_TYPE is Content-Type.
setHeader($name, $value)
setUri($uri, $preserveHost)
unsetHeader($name)
withAttribute($name, $value)Return an instance with the specified derived request attribute.
withAttributes($attrs)Return an instance with several derived request attributes set at once (merged via
withoutAttribute($name)Return an instance that removes the specified derived request attribute.
withParsedBody($data)Return an instance with the specified body parameters.
withRequestTarget($requestTarget)Return an instance with the specific request-target.
withUri($uri, $preserveHost)Returns an instance with the provided URI.
__clone()
__construct($uri, $headers)
__toString()

Properties4

attributes

protected array $attributes = []
Type
array

body

protected MMO\core\interfaces\iArray|array|null $body
Type
iArray | array | null

target

protected ?string $target = null
Type
null | string

uri

protected MMO\core\helpers\Uri $uri
Type
Uri

Methods22

debugName()

aRequest.php:40
function debugName()
returnsa short identifier for logs, e.g. '(Request)GET|https://example.com/foo'

getAttribute($name, $default)

aRequest.php:301

Retrieve a single derived request attribute.

function getAttribute(string $name, mixed $default = null): mixedRetrieves a single derived request attribute as described in getAttributes(). If the attribute has not been previously set, returns the default value as provided. This method obviates the need for a hasAttribute() method, as it allows specifying a default value to return if the attribute is not found.
See
getAttributes()
$namestringThe attribute name.
$default = nullmixedDefault value to return if the attribute does not exist.
returnsmixed
$req->getAttribute('user', null);

getAttributes()

aRequest.php:281

Retrieve attributes derived from the request.

function getAttributes(): arrayThe request "attributes" may be used to allow injection of any parameters derived from the request: e.g., the results of path match operations; the results of decrypting cookies; the results of deserializing non-form-encoded message bodies; etc. Attributes will be application and request specific, and CAN be mutable.
returnsarrayAttributes derived from the request.
$req->getAttributes(); // e.g. ['controller' => $controller, 'user' => $user]

getParsedBody()

aRequest.php:228

Retrieve any parameters provided in the request body.

function getParsedBody(): ArrayAccess|array|nullIf the request Content-Type is either application/x-www-form-urlencoded or multipart/form-data, and the request method is POST, this method MUST return the contents of $_POST. Otherwise, this method may return any results of deserializing the request 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.
returnsArrayAccess | array | nullThe deserialized body parameters, if any. These will typically be an array or object.
$req->getParsedBody(); // e.g. ['name' => 'value'], or null if nothing was parsed

getRequestTarget()

aRequest.php:129

Retrieves the message's request target.

function getRequestTarget(): stringRetrieves the message's request-target either as it will appear (for clients), as it appeared at request (for servers), or as it was specified for the instance (see withRequestTarget()). In most cases, this will be the origin-form of the composed URI, unless a value was provided to the concrete implementation (see withRequestTarget() below). If no URI is available, and no request-target has been specifically provided, this method MUST return the string "/".
returnsstring
$req->getRequestTarget(); // e.g. '/foo?x=1', derived from the URI, unless withRequestTarget() was used

getServerParams()

aRequest.php:374

Retrieve server parameters.

function getServerParams(): arrayRetrieves data related to the incoming request environment, typically derived from PHP's $_SERVER superglobal. The data IS NOT REQUIRED to originate from $_SERVER.
returnsarray
$req->getServerParams(); // $_SERVER

getUri($mutable)

aRequest.php:168

Retrieves the URI instance.

function getUri(bool $mutable = false): Psr\Http\Message\UriInterfaceThis method MUST return a UriInterface instance.
$mutable = falseboolif true, return a mutable clone of the URI instead of the shared immutable one
returnsUriInterfaceReturns a UriInterface instance representing the URI of the request.
$req->getUri(); // the request's Uri instance

HeaderName($name)

staticaRequest.php:78

The name of the header php's $_SERVER calls $name -- the way a web server hands php a request's headers: HTTP_X_CSRF_TOKEN is X-Csrf-Token, CONTENT_TYPE is Content-Type. Any other name is returned as it is.

static function HeaderName(string $name): stringA request sets and reads its headers through it: a header given as `$_SERVER` has it is kept under its own name, and `getHeaderLine('HTTP_RANGE')` still finds the `Range` header.
$namestring
returnsstring
Request::HeaderName('HTTP_IF_NONE_MATCH'); // 'If-None-Match'Request::HeaderName('DOCUMENT_ROOT'); // 'DOCUMENT_ROOT': not a header

setUri($uri, $preserveHost)

aRequest.php:54
protected function setUri($uri, bool $preserveHost = true)
$uri
$preserveHost = trueboolsee withUri for the exact semantics
returns

withAttribute($name, $value)

aRequest.php:321

Return an instance with the specified derived request attribute.

function withAttribute(string $name, mixed $value): selfThis method allows setting a single derived request attribute as described in getAttributes(). 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 attribute.
See
getAttributes()
$namestringThe attribute name.
$valuemixedThe value of the attribute.
returnsself
$req->withAttribute('user', $user);

withAttributes($attrs)

aRequest.php:334

Return an instance with several derived request attributes set at once (merged via

function withAttributes(array $attrs): self
See
merge, so an existing attribute not present in $attrs is kept).
$attrsarrayname => value
returnsself
$req->withAttributes(['user' => $user, 'role' => 'admin']);

withoutAttribute($name)

aRequest.php:355

Return an instance that removes the specified derived request attribute.

function withoutAttribute(string $name): selfThis method allows removing a single derived request attribute as described in getAttributes(). This method MUST be implemented in such a way as to retain the immutability of the message, and MUST return an instance that removes the attribute.
See
getAttributes()
$namestringThe attribute name.
returnsselfa clone without $name; or $this unchanged (no clone) if $name was never set to begin with
$req->withoutAttribute('user');

withParsedBody($data)

aRequest.php:262

Return an instance with the specified body parameters.

function withParsedBody(ArrayAccess|array|null $data): selfThese MAY be injected during instantiation. If the request Content-Type is either application/x-www-form-urlencoded or multipart/form-data, and the request method is POST, use this method ONLY to inject the contents of $_POST. The data IS NOT REQUIRED to come from $_POST, but MUST be the results of deserializing the request body content. Deserialization/parsing returns structured data, and, as such, this method ONLY accepts arrays or objects, or a null value if nothing was available to parse. As an example, if content negotiation determines that the request data is a JSON payload, this method could be used to create a request instance with the deserialized parameters. 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 body parameters.
$dataArrayAccess | array | nullThe deserialized body data. This will typically be in an array or object.
returnsself
throwsif an unsupported argument type is provided.
$req->withParsedBody(['name' => 'value']);$req->withParsedBody(null); // explicitly "nothing was available to parse"

withRequestTarget($requestTarget)

aRequest.php:151

Return an instance with the specific request-target.

function withRequestTarget(string $requestTarget): selfIf the request needs a non-origin-form request-target — e.g., for specifying an absolute-form, authority-form, or asterisk-form — this method may be used to create an instance with the specified request-target, verbatim. 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 changed request target.
$requestTargetstring
returnsself
$req->withRequestTarget('*'); // e.g. for an OPTIONS * request

withUri($uri, $preserveHost)

aRequest.php:204

Returns an instance with the provided URI.

function withUri(Psr\Http\Message\UriInterface $uri, $preserveHost = false): selfThis method MUST update the Host header of the returned request by default if the URI contains a host component. If the URI does not contain a host component, any pre-existing Host header MUST be carried over to the returned request. You can opt-in to preserving the original state of the Host header by setting `$preserveHost` to `true`. When `$preserveHost` is set to `true`, this method interacts with the Host header in the following ways: - If the Host header is missing or empty, and the new URI contains a host component, this method MUST update the Host header in the returned request. - If the Host header is missing or empty, and the new URI does not contain a host component, this method MUST NOT update the Host header in the returned request. - If a Host header is present and non-empty, this method MUST NOT update the Host header in the returned request. 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 new UriInterface instance.
$uriUriInterfaceNew request URI to use.
$preserveHost = falsePreserve the original state of the Host header.
returnsself
$req->withUri(Uri::Immutable('https://other.com/bar')); // Host header updated to 'other.com'$req->withUri(Uri::Immutable('https://other.com/bar'), true); // Host header left as-is, if already set

__construct($uri, $headers)

aRequest.php:30
function __construct($uri, array $headers = [])
$uri
$headers = []array
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
getCookieParams()ServerRequestInterfaceRetrieve cookies.
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 …
getMethod()RequestInterfaceRetrieves the HTTP method of the request.
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.
getQueryParams()ServerRequestInterfaceRetrieve query string arguments.
getUploadedFiles()ServerRequestInterfaceRetrieve normalized file upload data.
getUserAgent()aMessage
HasListener($handler)aMessage
isHTML()aMessage
isIe()aMessage
isIphone()aMessage
isJSON()aMessage
isMac()aMessage
isMobile()aMessage
isWindows()aMessage
jsonSerialize()JsonSerializable
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.
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).
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.
withCookieParams($cookies)ServerRequestInterfaceReturn an instance with the specified cookies.
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).
withMethod($method)RequestInterfaceReturn an instance with the provided HTTP method.
withoutHeader($name)aMessageReturn an instance without the specified header.
withProtocolVersion($version)aMessageReturn an instance with the specified HTTP protocol version.
withQueryParams($query)ServerRequestInterfaceReturn an instance with the specified query string arguments.
withUploadedFiles($uploadedFiles)ServerRequestInterfaceCreate a new instance with the specified uploaded files.