class Request implements IRequest

HttpRequest provides access scheme for request sent via HTTP.

Properties

UrlScript read-only $url
array read-only $query
array read-only $post
array read-only $files
array read-only $cookies
string read-only $method
array read-only $headers
UrlImmutable|null read-only $referer
bool read-only $secured
bool read-only $ajax
string|null read-only $remoteAddress
string|null read-only $remoteHost
string|null read-only $rawBody

Methods

__construct(UrlScript $url, array $post = [], array $files = [], array $cookies = [], array $headers = [], string $method = 'GET', string|null $remoteAddress = null, string|null $remoteHost = null, callable|null $rawBodyCallback = null, string|null $user = null, string|null $password = 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 variable provided to the script via URL query ($_GET).

mixed
getPost(string|null $key = null)

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

FileUpload|null
getFile(string $key)

Returns uploaded file.

array
getFiles()

Returns tree of upload files in a normalized structure, with each leaf an instance of Nette\Http\FileUpload.

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() deprecated

What URL did the user come from? Beware, it is not reliable at all.

UrlImmutable|null
getOrigin()

What origin did the user come from? It contains scheme, hostname and port.

bool
isSecured()

Is the request sent via secure channel (https)?

bool
isSameSite()

Is the request coming from the same site and is initiated by clicking on a link?

bool
isAjax()

Is it an 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
getUser()

No description

string|null
getPassword()

No description

string|null
detectLanguage(array $langs)

Returns the most preferred language by browser. Uses the Accept-Language header. If no match is reached, it returns null.

Details

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

No description

Parameters

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

at line 63
Request withUrl(UrlScript $url)

Returns a clone with a different URL.

Parameters

UrlScript $url

Return Value

Request

at line 74
UrlScript getUrl()

Returns the URL of the request.

Return Value

UrlScript

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

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

If no key is passed, returns the entire array.

Parameters

string|null $key

Return Value

mixed

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

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

If no key is passed, returns the entire array.

Parameters

string|null $key

Return Value

mixed

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

Returns uploaded file.

Parameters

string $key

Return Value

FileUpload|null

at line 125
array getFiles()

Returns tree of upload files in a normalized structure, with each leaf an instance of Nette\Http\FileUpload.

Return Value

array

at line 134
mixed getCookie(string $key)

Returns a cookie or null if it does not exist.

Parameters

string $key

Return Value

mixed

at line 143
array getCookies()

Returns all cookies.

Return Value

array

at line 155
string getMethod()

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

Return Value

string

at line 164
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 173
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 183
array getHeaders()

Returns all HTTP headers as associative array.

Return Value

array

at line 193
UrlImmutable|null getReferer() deprecated

deprecated deprecated in favor of the getOrigin()

What URL did the user come from? Beware, it is not reliable at all.

Return Value

UrlImmutable|null

at line 204
UrlImmutable|null getOrigin()

What origin did the user come from? It contains scheme, hostname and port.

Return Value

UrlImmutable|null

at line 220
bool isSecured()

Is the request sent via secure channel (https)?

Return Value

bool

at line 229
bool isSameSite()

Is the request coming from the same site and is initiated by clicking on a link?

Return Value

bool

at line 238
bool isAjax()

Is it an AJAX request?

Return Value

bool

at line 247
string|null getRemoteAddress()

Returns the IP address of the remote client.

Return Value

string|null

at line 256
string|null getRemoteHost()

Returns the host of the remote client.

Return Value

string|null

at line 269
string|null getRawBody()

Returns raw content of HTTP request body.

Return Value

string|null

at line 275
string|null getUser()

No description

Return Value

string|null

at line 281
string|null getPassword()

No description

Return Value

string|null

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

Returns the most preferred language by browser. Uses the Accept-Language header. If no match is reached, it returns null.

Parameters

array $langs

supported languages

Return Value

string|null

Traits

SmartObject