\OCPIRequest

This interface provides an immutable object with with accessors to request variables and headers.

Access request variables by method and name.

Examples:

$request->post['myvar']; // Only look for POST variables $request->myvar; or $request->{'myvar'}; or $request->{$myvar} Looks in the combined GET, POST and urlParams array.

If you access e.g. ->post but the current HTTP request method is GET a \LogicException will be thrown.

NOTE:

  • When accessing ->put a stream resource is returned and the accessor will return false on subsequent access to ->put or ->patch.
  • When accessing ->patch and the Content-Type is either application/json or application/x-www-form-urlencoded (most cases) it will act like ->get and ->post and return an array. Otherwise the raw data will be returned.

Summary

Methods
Constants
getHeader()
getParam()
getParams()
getMethod()
getUploadedFile()
getEnv()
getCookie()
passesCSRFCheck()
getId()
getRemoteAddress()
getServerProtocol()
getHttpProtocol()
getRequestUri()
getRawPathInfo()
getPathInfo()
getScriptName()
isUserAgent()
getInsecureServerHost()
getServerHost()
No constants found
No protected methods found
N/A
No private methods found
N/A

Methods

getHeader()

getHeader(string  $name) : string

Parameters

string $name

Returns

string

getParam()

getParam(string  $key, mixed  $default = null) : mixed

Lets you access post and get parameters by the index In case of json requests the encoded json body is accessed

Parameters

string $key

the key which you want to access in the URL Parameter placeholder, $_POST or $_GET array. The priority how they're returned is the following:

  1. URL parameters
  2. POST parameters
  3. GET parameters
mixed $default

If the key is not found, this value will be returned

Returns

mixed —

the content of the array

getParams()

getParams() : array

Returns all params that were received, be it from the request

(as GET or POST) or through the URL by the route

Returns

array —

the array with all parameters

getMethod()

getMethod() : string

Returns the method of the request

Returns

string —

the method of the request (POST, GET, etc)

getUploadedFile()

getUploadedFile(string  $key) : array

Shortcut for accessing an uploaded file through the $_FILES array

Parameters

string $key

the key that will be taken from the $_FILES array

Returns

array —

the file in the $_FILES element

getEnv()

getEnv(string  $key) : array

Shortcut for getting env variables

Parameters

string $key

the key that will be taken from the $_ENV array

Returns

array —

the value in the $_ENV element

getCookie()

getCookie(string  $key) : string

Shortcut for getting cookie variables

Parameters

string $key

the key that will be taken from the $_COOKIE array

Returns

string —

the value in the $_COOKIE element

passesCSRFCheck()

passesCSRFCheck() : boolean

Checks if the CSRF check was correct

Returns

boolean —

true if CSRF check passed

getId()

getId() : string

Returns an ID for the request, value is not guaranteed to be unique and is mostly meant for logging If `mod_unique_id` is installed this value will be taken.

Returns

string

getRemoteAddress()

getRemoteAddress() : string

Returns the remote address, if the connection came from a trusted proxy and `forwarded_for_headers` has been configured then the IP address specified in this header will be returned instead.

Do always use this instead of $_SERVER['REMOTE_ADDR']

Returns

string —

IP address

getServerProtocol()

getServerProtocol() : string

Returns the server protocol. It respects reverse proxy servers and load balancers.

Returns

string —

Server protocol (http or https)

getHttpProtocol()

getHttpProtocol() : string

Returns the used HTTP protocol.

Returns

string —

HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0.

getRequestUri()

getRequestUri() : string

Returns the request uri, even if the website uses one or more reverse proxies

Returns

string

getRawPathInfo()

getRawPathInfo() : string

Get raw PathInfo from request (not urldecoded)

Throws

\Exception

Returns

string —

Path info

getPathInfo()

getPathInfo() : string|false

Get PathInfo from request

Throws

\Exception

Returns

string|false —

Path info or false when not found

getScriptName()

getScriptName() : string

Returns the script name, even if the website uses one or more reverse proxies

Returns

string —

the script name

isUserAgent()

isUserAgent(array  $agent) : boolean

Checks whether the user agent matches a given regex

Parameters

array $agent

array of agent names

Returns

boolean —

true if at least one of the given agent matches, false otherwise

getInsecureServerHost()

getInsecureServerHost() : string

Returns the unverified server host from the headers without checking whether it is a trusted domain

Returns

string —

Server host

getServerHost()

getServerHost() : string

Returns the server host from the headers, or the first configured trusted domain if the host isn't in the trusted list

Returns

string —

Server host