objects

Request

The current HTTP request: path segments, query, post body, uploaded files, and whether htmx sent it.

$request Phlat\Request 15 methods
Properties (15)
$request->method string readonly
$request->scheme string readonly
$request->hostname string readonly
$request->path string readonly
$request->valid bool readonly False when the path strays outside the URL grammar (see V::slug() and V::filename()); App answers it with a 404 rather than looking anything up.
$request->httpUrl string readonly
$request->urls array readonly
$request->segments array readonly
$request->block ?string readonly
$request->revision ?string readonly
$request->ssl bool readonly
$request->ip ?string readonly
$request->userAgent ?string readonly
$request->referrer ?string readonly
$request->url ?string readonly
Show
  • acceptsJson Returns true if the client asked for JSON (Accept: application/json), as an API client does.
  • bearer Returns the bearer token from the Authorization header, or null if absent.
  • body Returns the raw request body.
  • file Returns the raw $_FILES entry for $key, or null if absent.
  • files Returns the uploads for $key as a list of single-file $_FILES entries, for name="key" and name="key[]" alike.
  • isCrossOrigin Returns true if a browser sent the request from another origin: Sec-Fetch-Site, else Origin against the host.
  • isFrame Returns true if the request is a browser iframe load (Sec-Fetch-Dest: iframe).
  • isPartial Returns true if the request was made by a hypermedia client (e.g.
  • json Returns the request body decoded as a JSON array, empty if absent or invalid.
  • nonce Returns a random nonce, generated once and memoized for the lifetime of this request.
  • post Returns a POST body parameter by key, or null if absent.
  • postArray Returns a POST body parameter as an array (e.g. submitted via name="foo[bar]" inputs), or null if absent or not array-shaped.
  • queries Returns every query string parameter.
  • query Returns a query string parameter by key, or null if absent.
  • segment Returns the URL segment at $position (1-indexed), or null if out of bounds.

Methods

$request->acceptsJson(): bool

Returns true if the client asked for JSON (Accept: application/json), as an API client does.

Returns bool

phlat/src/Request.php:91
$request->bearer(): ?string

Returns the bearer token from the Authorization header, or null if absent.

Returns ?string

phlat/src/Request.php:131
$request->body(): string

Returns the raw request body.

Returns string

phlat/src/Request.php:119
$request->file(string $key): ?array

Returns the raw $_FILES entry for $key, or null if absent.

Parameters (1)
$key string

Returns ?array

phlat/src/Request.php:168
$request->files(string $key): array

Returns the uploads for $key as a list of single-file $_FILES entries, for name="key" and name="key[]" alike.

Parameters (1)
$key string

Returns array

phlat/src/Request.php:174
$request->isCrossOrigin(): bool

Returns true if a browser sent the request from another origin: Sec-Fetch-Site, else Origin against the host.

Neither header means no browser, so no CSRF victim.

Returns bool

phlat/src/Request.php:97
$request->isFrame(): bool

Returns true if the request is a browser iframe load (Sec-Fetch-Dest: iframe).

Returns bool

phlat/src/Request.php:107
$request->isPartial(): bool

Returns true if the request was made by a hypermedia client (e.g.

HTMX).

Returns bool

phlat/src/Request.php:85
$request->json(): array

Returns the request body decoded as a JSON array, empty if absent or invalid.

Returns array

phlat/src/Request.php:125
$request->nonce(): string

Returns a random nonce, generated once and memoized for the lifetime of this request.

Use in a Content-Security-Policy header and matching hx-nonce/script/style attributes.

Returns string

phlat/src/Request.php:113
$request->post(string $key): ?string

Returns a POST body parameter by key, or null if absent.

Parameters (1)
$key string

Returns ?string

phlat/src/Request.php:156
$request->postArray(string $key): ?array

Returns a POST body parameter as an array (e.g. submitted via name="foo[bar]" inputs), or null if absent or not array-shaped.

Parameters (1)
$key string

Returns ?array

phlat/src/Request.php:162
$request->queries(): array

Returns every query string parameter.

Returns array

phlat/src/Request.php:150
$request->query(string $key): ?string

Returns a query string parameter by key, or null if absent.

Parameters (1)
$key string

Returns ?string

phlat/src/Request.php:144
$request->segment(int $position): ?string

Returns the URL segment at $position (1-indexed), or null if out of bounds.

Parameters (1)
$position int

Returns ?string

phlat/src/Request.php:138