class RequestUtil
Constants
| INTERNAL_ATTRIBUTE |
Attribute key marking a request as an internal API call (dispatched via {\Flarum\Api\Client}, e.g. when a frontend page preloads its API document) rather than a request from an external client. |
| POST_SOURCE_ATTRIBUTE |
Attribute key holding the {PostSource} of the request's posts. |
Methods
Determine if the request is an API request. We do not manually set the `Accepts` header for API requests, so we need to check the priority list to determine whether it is or not.
Whether this request was dispatched internally. Internal requests are not held to the JSON:API spec's strict query-parameter validation: a frontend page forwards the browser's query string (which may carry tracking params like `fbclid`) into the API client, and those must not 400 the page.
Determine the client's preferred content type out of the given list.
The class the forum puts on `<html>` to tell guests from signed-in users: `guest-user` or `logged-in`. Standalone pages that use `layouts/basic` pass it to the view as `actorClass`, so a theme can rely on it across them.
Record how this request reached the forum, so posts it creates show it.
No description
No description
No description
No description
Details
at
line 25
static bool
isApiRequest( ServerRequestInterface $request)
Determine if the request is an API request. We do not manually set the `Accepts` header for API requests, so we need to check the priority list to determine whether it is or not.
Normal browsing requests will have `text/html` as their preferred content type, while API will have `* / *`.
at
line 35
static bool
isHtmlRequest( ServerRequestInterface $request)
at
line 47
static ServerRequestInterface
withInternal( ServerRequestInterface $request)
at
line 58
static bool
isInternal( ServerRequestInterface $request)
Whether this request was dispatched internally. Internal requests are not held to the JSON:API spec's strict query-parameter validation: a frontend page forwards the browser's query string (which may carry tracking params like `fbclid`) into the API client, and those must not 400 the page.
at
line 70
static string
getPreferredContentType( ServerRequestInterface $request, array $types)
Determine the client's preferred content type out of the given list.
at
line 111
static string|null
getActorHtmlClass( ServerRequestInterface $request)
The class the forum puts on `<html>` to tell guests from signed-in users: `guest-user` or `logged-in`. Standalone pages that use `layouts/basic` pass it to the view as `actorClass`, so a theme can rely on it across them.
It reflects the actor as far as the request got. The reference is shared and filled in by the authentication middleware, so an error thrown before that has run (for example in `StartSession`, `RememberFromCookie`, `CollectGarbage` or an extension's middleware) still sees the `Guest` that `InjectActorReference` set first, and a signed-in visitor gets `guest-user`. That errs on the safe side. Returns null when the request has no actor reference at all.
at
line 143
static ServerRequestInterface
withPostSource( ServerRequestInterface $request, PostSource|null $source)
Record how this request reached the forum, so posts it creates show it.
Pass null for a request from the forum's own interface.