class Request implements IRequest

HttpRequest provides access scheme for request sent via HTTP.

Traits

Strict class for better experience.

Methods

__construct(UrlScript $url, array $post = null, array $files = null, array $cookies = null, array $headers = null, string $method = null, string $remoteAddress = null, string $remoteHost = null, callable $rawBodyCallback = null)

No description

withUrl(UrlScript $url)

No description

getUrl()

Returns URL object.

mixed
getQuery(string $key = null)

Returns variable provided to the script via URL query ($_GET).

mixed
getPost(string $key = null)

Returns variable provided to the script via POST method ($_POST).

FileUpload|array|null
getFile(string $key)

Returns uploaded file.

array
getFiles()

Returns uploaded files.

mixed
getCookie(string $key)

Returns variable provided to the script via HTTP cookies.

array
getCookies()

Returns variables provided to the script via HTTP cookies.

string
getMethod()

Returns HTTP request method (GET, POST, HEAD, PUT, .

bool
isMethod(string $method)

Checks if the request method is the given one.

string|null
getHeader(string $header)

Return the value of the HTTP header. Pass the header name as the plain, HTTP-specified header name (e.g. 'Accept-Encoding').

array
getHeaders()

Returns all HTTP headers.

UrlImmutable|null
getReferer()

Returns referrer.

bool
isSecured()

Is the request sent via secure channel (https)?

bool
isSameSite()

Is the request sent from the same origin?

bool
isAjax()

Is AJAX request?

string|null
getRemoteAddress()

Returns the IP address of the remote client.

string|null
getRemoteHost()

Returns the host of the remote client.

string|null
getRawBody()

Returns raw content of HTTP request body.

string|null
detectLanguage(array $langs)

Parse Accept-Language header and returns preferred language.

Details

at line 64
__construct(UrlScript $url, array $post = null, array $files = null, array $cookies = null, array $headers = null, string $method = null, string $remoteAddress = null, string $remoteHost = null, callable $rawBodyCallback = null)

Parameters

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

at line 82
Request withUrl(UrlScript $url)

Parameters

UrlScript $url

Return Value

Request

at line 93
UrlScript getUrl()

Returns URL object.

Return Value

UrlScript

at line 107
mixed getQuery(string $key = null)

Returns variable provided to the script via URL query ($_GET).

If no key is passed, returns the entire array.

Parameters

string $key

Return Value

mixed

at line 123
mixed getPost(string $key = null)

Returns variable provided to the script via POST method ($_POST).

If no key is passed, returns the entire array.

Parameters

string $key

Return Value

mixed

at line 138
FileUpload|array|null getFile(string $key)

Returns uploaded file.

Parameters

string $key

Return Value

FileUpload|array|null

at line 147
array getFiles()

Returns uploaded files.

Return Value

array

at line 157
mixed getCookie(string $key)

Returns variable provided to the script via HTTP cookies.

Parameters

string $key

Return Value

mixed

at line 169
array getCookies()

Returns variables provided to the script via HTTP cookies.

Return Value

array

at line 181
string getMethod()

Returns HTTP request method (GET, POST, HEAD, PUT, .

..). The method is case-sensitive.

Return Value

string

at line 190
bool isMethod(string $method)

Checks if the request method is the given one.

Parameters

string $method

Return Value

bool

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

Return the value of the HTTP header. Pass the header name as the plain, HTTP-specified header name (e.g. 'Accept-Encoding').

Parameters

string $header

Return Value

string|null

at line 213
array getHeaders()

Returns all HTTP headers.

Return Value

array

at line 222
UrlImmutable|null getReferer()

Returns referrer.

Return Value

UrlImmutable|null

at line 233
bool isSecured()

Is the request sent via secure channel (https)?

Return Value

bool

at line 242
bool isSameSite()

Is the request sent from the same origin?

Return Value

bool

at line 251
bool isAjax()

Is AJAX request?

Return Value

bool

at line 260
string|null getRemoteAddress()

Returns the IP address of the remote client.

Return Value

string|null

at line 269
string|null getRemoteHost()

Returns the host of the remote client.

Return Value

string|null

at line 281
string|null getRawBody()

Returns raw content of HTTP request body.

Return Value

string|null

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

Parse Accept-Language header and returns preferred language.

Parameters

array $langs supported languages

Return Value

string|null