class Request implements IRequest

Immutable representation of an HTTP request with access to URL, headers, cookies, uploaded files, and body.

Properties

UrlScript read-only $url
array<string,mixed> read-only $query
array<string,mixed> read-only $post
array<string,mixed> read-only $files
array<string,string> read-only $cookies
string read-only $method
array<string,string> read-only $headers
UrlImmutable read-only $referer
bool read-only $secured
bool read-only $ajax
?string read-only $remoteAddress
?string read-only $rawBody

Methods

__construct(UrlScript $url, array $post = [], array $files = [], array $cookies = [], array $headers = [], string $method = 'GET', string|null $remoteAddress = null, callable|null $rawBodyCallback = null)

No description

withUrl(UrlScript $url)

Returns a clone with a different URL.

getUrl()

Returns the URL of the request.

mixed
getQuery(string|null $key = null)

Returns a URL query parameter, or all parameters as an array if no key is given.

mixed
getPost(string|null $key = null)

Returns a POST parameter, or all POST parameters as an array if no key is given.

FileUpload|null
getFile(string $key)

Returns the uploaded file for the given key, or null if not present.

array
getFiles()

Returns the tree of uploaded files, with each leaf being a FileUpload instance.

mixed
getCookie(string $key)

Returns a cookie or null if it does not exist.

array
getCookies()

Returns all cookies.

string
getMethod()

Returns the HTTP method with which the request was made (GET, POST, HEAD, PUT, ...).

bool
isMethod(string $method)

Checks the HTTP method with which the request was made. The parameter is case-insensitive.

string|null
getHeader(string $header)

Returns an HTTP header or null if it does not exist. The parameter is case-insensitive.

array
getHeaders()

Returns all HTTP headers as associative array.

UrlImmutable|null
getReferer()

No description

UrlImmutable|null
getOrigin()

Returns the request origin (scheme + host + port) from the Origin header, or null if absent or invalid.

bool
isSecured()

Checks whether the request was sent via a secure channel (HTTPS).

bool
isSameSite() deprecated

Checks whether the request originated from your own site (same-site), i.e. it was not triggered from a foreign website. Serves as a CSRF-like protection for forms and signals.

bool
isFrom(FetchSite> $site, FetchDest>|null $dest = null, ?bool $user = null)

Checks whether the request matches the given Sec-Fetch-Site, Sec-Fetch-Dest and Sec-Fetch-User values.

bool
isAjax()

Checks whether the request was made via AJAX (X-Requested-With: XMLHttpRequest).

string|null
getRemoteAddress()

Returns the IP address of the remote client.

string|null
getRawBody()

Returns raw content of HTTP request body.

array|null
getBasicCredentials()

Returns basic HTTP authentication credentials.

string|null
detectLanguage(array $langs)

Returns the most preferred language from the Accept-Language header that matches one of the supported languages, or null if no match is found.

Details

at line 45
__construct(UrlScript $url, array $post = [], array $files = [], array $cookies = [], array $headers = [], string $method = 'GET', string|null $remoteAddress = null, callable|null $rawBodyCallback = null)

No description

Parameters

UrlScript $url
array $post
array $files
array $cookies
array $headers
string $method
string|null $remoteAddress
callable|null $rawBodyCallback

at line 66
Request withUrl(UrlScript $url)

Returns a clone with a different URL.

Parameters

UrlScript $url

Return Value

Request

at line 77
UrlScript getUrl()

Returns the URL of the request.

Return Value

UrlScript

at line 89
mixed getQuery(string|null $key = null)

Returns a URL query parameter, or all parameters as an array if no key is given.

Parameters

string|null $key

Return Value

mixed

at line 103
mixed getPost(string|null $key = null)

Returns a POST parameter, or all POST parameters as an array if no key is given.

Parameters

string|null $key

Return Value

mixed

at line 119
FileUpload|null getFile(string $key)

Returns the uploaded file for the given key, or null if not present.

Accepts a string key or an array of keys for nested file structures (e.g. ['form', 'avatar']).

Parameters

string $key

Return Value

FileUpload|null

at line 130
array getFiles()

Returns the tree of uploaded files, with each leaf being a FileUpload instance.

Return Value

array

at line 139
mixed getCookie(string $key)

Returns a cookie or null if it does not exist.

Parameters

string $key

Return Value

mixed

at line 149
array getCookies()

Returns all cookies.

Return Value

array

at line 161
string getMethod()

Returns the HTTP method with which the request was made (GET, POST, HEAD, PUT, ...).

Return Value

string

at line 170
bool isMethod(string $method)

Checks the HTTP method with which the request was made. The parameter is case-insensitive.

Parameters

string $method

Return Value

bool

at line 179
string|null getHeader(string $header)

Returns an HTTP header or null if it does not exist. The parameter is case-insensitive.

Parameters

string $header

Return Value

string|null

at line 190
array getHeaders()

Returns all HTTP headers as associative array.

Return Value

array

at line 196
UrlImmutable|null getReferer()

No description

Return Value

UrlImmutable|null

at line 209
UrlImmutable|null getOrigin()

Returns the request origin (scheme + host + port) from the Origin header, or null if absent or invalid.

Return Value

UrlImmutable|null

at line 222
bool isSecured()

Checks whether the request was sent via a secure channel (HTTPS).

Return Value

bool

at line 233
bool isSameSite() deprecated

deprecated use isFrom()

Checks whether the request originated from your own site (same-site), i.e. it was not triggered from a foreign website. Serves as a CSRF-like protection for forms and signals.

Return Value

bool

at line 245
bool isFrom(FetchSite> $site, FetchDest>|null $dest = null, ?bool $user = null)

Checks whether the request matches the given Sec-Fetch-Site, Sec-Fetch-Dest and Sec-Fetch-User values.

Parameters

FetchSite> $site
FetchDest>|null $dest
?bool $user

Return Value

bool

at line 267
bool isAjax()

Checks whether the request was made via AJAX (X-Requested-With: XMLHttpRequest).

Return Value

bool

at line 276
string|null getRemoteAddress()

Returns the IP address of the remote client.

Return Value

string|null

at line 285
string|null getRawBody()

Returns raw content of HTTP request body.

Return Value

string|null

at line 295
array|null getBasicCredentials()

Returns basic HTTP authentication credentials.

Return Value

array|null

at line 315
string|null detectLanguage(array $langs)

Returns the most preferred language from the Accept-Language header that matches one of the supported languages, or null if no match is found.

Parameters

array $langs

supported language codes (e.g. ['en', 'cs', 'de'])

Return Value

string|null

Traits

SmartObject