Documentation

No matching pages.

API

Config

Facade

Lifecycle

Class: Request

Full name: Azera\Http\Request

Class Request A simple HTTP request handler that abstracts away PHP's superglobals and provides convenient methods to access request data.

It also handles method overrides, proxy headers, content negotiation, and file uploads in a consistent way.

Public methods

__construct() ·

public function __construct(array|null $server = null, array|null $get = null, array|null $post = null, array|null $files = null, bool $trustProxyHeaders = false, array|null $cookies = null): mixed

Parameters

Name Type Default Description
$server array|null null
$get array|null null
$post array|null null
$files array|null null
$trustProxyHeaders bool false
$cookies array|null null

Return value

  • Type: mixed

body() ·

public function body(): string

Get the raw request body Caches the body since php://input can only be read once

Return value

  • Type: string

setRawBody() ·

public function setRawBody(string $body): static

Set the raw request body.

Exists for application-server workers (RoadRunner, Volucer), where the request does not arrive through the SAPI and php://input is not the body. In a worker, stdin carries the server's own protocol frames, so letting body() fall back to php://input would consume protocol bytes and desynchronise the stream permanently. A worker adapter injects the body it was handed, and body() then never reads the pipe.

Set it even when the body is empty. body() only falls back when the value is null, so an empty string is what stops the read — a bodyless GET in a worker is exactly the case that must not touch php://input.

Parameters

Name Type Default Description
$body string -

Return value

  • Type: static

jsonBody() ·

public function jsonBody(bool $assoc = true): mixed

Get and parse JSON request body

Parameters

Name Type Default Description
$assoc bool true When true, returns associative arrays. When false, returns objects

Return value

  • Type: mixed
  • Description: Returns the parsed JSON data, or null on error

Throws

  • RuntimeException if the JSON body cannot be parsed

input() ·

public function input(string|null $name = null, mixed $default = null): mixed

Get an input parameter from the request (POST takes precedence over GET)

Parameters

Name Type Default Description
$name string|null null
$default mixed null

Return value

  • Type: mixed

query() ·

public function query(string|null $name = null, mixed $default = null): mixed

Get a query parameter from the request

Parameters

Name Type Default Description
$name string|null null
$default mixed null

Return value

  • Type: mixed

get() ·

public function get(string|null $name = null, mixed $default = null): mixed

Get a query parameter from the request

Parameters

Name Type Default Description
$name string|null null
$default mixed null

Return value

  • Type: mixed

post() ·

public function post(string|null $name = null, mixed $default = null): mixed

Get a POST parameter from the request

Parameters

Name Type Default Description
$name string|null null
$default mixed null

Return value

  • Type: mixed

cookies() ·

public function cookies(): array

Get the cookies the client sent.

Return value

  • Type: array

public function cookie(string $name, mixed $default = null): mixed

Get a cookie value from the request

Parameters

Name Type Default Description
$name string -
$default mixed null

Return value

  • Type: mixed

server() ·

public function server(string|null $name = null, mixed $default = null): mixed

Get a server variable from the request

Parameters

Name Type Default Description
$name string|null null
$default mixed null

Return value

  • Type: mixed

header() ·

public function header(string $name, mixed $default = null): mixed

Get a request header value (case-insensitive).

Parameters

Name Type Default Description
$name string -
$default mixed null

Return value

  • Type: mixed

hasInput() ·

public function hasInput(string $name): bool

Parameters

Name Type Default Description
$name string -

Return value

  • Type: bool

hasQuery() ·

public function hasQuery(string $name): bool

Parameters

Name Type Default Description
$name string -

Return value

  • Type: bool

hasPost() ·

public function hasPost(string $name): bool

Parameters

Name Type Default Description
$name string -

Return value

  • Type: bool

method() ·

public function method(): string

Get the HTTP method of the request, accounting for method overrides in POST requests

Return value

  • Type: string

isPost() ·

public function isPost(): bool

Checks whether the request method is POST

Return value

  • Type: bool

scheme() ·

public function scheme(): string

Get the request scheme (http or https)

Return value

  • Type: string

isSecure() ·

public function isSecure(): bool

Checks whether request has been made using HTTPS

Return value

  • Type: bool

host() ·

public function host(): string

Get the host name of the request, accounting for proxy headers and Host header

Return value

  • Type: string

port() ·

public function port(): int

Get the port number of the request, accounting for proxy headers and Host header

Return value

  • Type: int

uri() ·

public function uri(): string

Get the full URI of the request

Return value

  • Type: string

path() ·

public function path(): string

Get the path component of the request URI (without query string)

Return value

  • Type: string

clientIp() ·

public function clientIp(bool $trustForwarded = false): string|false

Get the client IP address, accounting for proxy headers if trusted

Parameters

Name Type Default Description
$trustForwarded bool false

Return value

  • Type: string|false

acceptableContent() ·

public function acceptableContent(bool $sort = false): array

Get the list of acceptable content types from the Accept header, with quality factors

Parameters

Name Type Default Description
$sort bool false Whether to sort by quality (highest first)

Return value

  • Type: array
  • Description: An array of ['accept' => string, 'quality' => float, ...] entries

bestAccept() ·

public function bestAccept(): string

Get the best acceptable content type from the Accept header

Return value

  • Type: string

languages() ·

public function languages(bool $sort = false): array

Get the list of acceptable languages from the Accept-Language header, with quality factors

Parameters

Name Type Default Description
$sort bool false Whether to sort by quality (highest first)

Return value

  • Type: array
  • Description: An array of ['language' => string, 'quality' => float, ...] entries

bestLanguage() ·

public function bestLanguage(): string

Get the best acceptable language from the Accept-Language header

Return value

  • Type: string

encodings() ·

public function encodings(bool $sort = false): array

Get the list of acceptable encodings from the Accept-Encoding header, with quality factors

Parameters

Name Type Default Description
$sort bool false Whether to sort by quality (highest first)

Return value

  • Type: array
  • Description: An array of ['encoding' => string, 'quality' => float, ...] entries

bestEncoding() ·

public function bestEncoding(): string

Get the best acceptable encoding from the Accept-Encoding header

Return value

  • Type: string

charsets() ·

public function charsets(bool $sort = false): array

Get the list of acceptable charsets from the Accept-Charset header, with quality factors

Parameters

Name Type Default Description
$sort bool false Whether to sort by quality (highest first)

Return value

  • Type: array
  • Description: An array of ['charset' => string, 'quality' => float, ...] entries

bestCharset() ·

public function bestCharset(): string

Get the best acceptable charset from the Accept-Charset header

Return value

  • Type: string

isJson() ·

public function isJson(): bool

Checks whether the request expects a JSON response based on Content-Type or Accept headers

Return value

  • Type: bool

isAjax() ·

public function isAjax(): bool

Checks whether the request is an AJAX request based on X-Requested-With header or if it expects JSON

Return value

  • Type: bool

basicAuth() ·

public function basicAuth(): array|null

Get Basic Auth credentials from the request, accounting for different server configurations

Return value

  • Type: array|null
  • Description: Returns ['username' => string, 'password' => string] or null if not present

authorization() ·

public function authorization(): array|null

Get any HTTP auth scheme from the request

Return value

  • Type: array|null
  • Description: Returns ['scheme' => string, 'token' => string] or null if not present

userAgent() ·

public function userAgent(): string

Get the User-Agent string from the request headers

Return value

  • Type: string

contentType() ·

public function contentType(): string

Get the Content-Type header from the request

Return value

  • Type: string

file() ·

public function file(string $key): Azera\Http\UploadedFile|null

Get the first uploaded file for a given field name, or null if not present

Parameters

Name Type Default Description
$key string -

Return value


files() ·

public function files(string $key): array

Get all uploaded files for a given field name, or an empty array if not present

Parameters

Name Type Default Description
$key string -

Return value

  • Type: array

Back to the Index