Nextcloud PHP API (master)

IRequest

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.
Tags
since
6.0.0

Table of Contents

Constants

JSON_CONTENT_TYPE_REGEX  = '/^application\/(?:[a-z0-9.-]+\+)?json\b/'
USER_AGENT_CLIENT_ANDROID  = '/^Mozilla\/5\.0 \(Android\) (?:ownCloud|Nextcloud)\-android\/([^ ]*).*$/'
USER_AGENT_CLIENT_DESKTOP  = '/^Mozilla\/5\.0 \([A-Za-z ]+\) (?:mirall|csyncoC)\/([^ ]*).*$/'
USER_AGENT_CLIENT_IOS  = '/^Mozilla\/5\.0 \(iOS\) (?:ownCloud|Nextcloud)\-iOS\/([^ ]*).*$/'
USER_AGENT_OUTLOOK_ADDON  = '/^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Outlook v([^ ]*).*$/'
USER_AGENT_TALK_ANDROID  = '/^Mozilla\/5\.0 \(Android\) Nextcloud\-Talk v([^ ]*).*$/'
USER_AGENT_TALK_DESKTOP  = '/^Mozilla\/5\.0 \((?!Android|iOS)[A-Za-z ]+\) Nextcloud\-Talk v([^ ]*).*$/'
USER_AGENT_TALK_IOS  = '/^Mozilla\/5\.0 \(iOS\) Nextcloud\-Talk v([^ ]*).*$/'
USER_AGENT_THUNDERBIRD_ADDON  = '/^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Thunderbird v([^ ]*).*$/'

Methods

getCookie()  : string|null
Shortcut for getting cookie variables
getEnv()  : array<string|int, mixed>
Shortcut for getting env variables
getHeader()  : string
getHttpProtocol()  : string
Returns the used HTTP protocol.
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.
getInsecureServerHost()  : string
Returns the unverified server host from the headers without checking whether it is a trusted domain
getMethod()  : string
Returns the method of the request
getParam()  : mixed
Lets you access post and get parameters by the index In case of json requests the encoded json body is accessed
getParams()  : array<string|int, mixed>
Returns all params that were received, be it from the request
getPathInfo()  : string|false
Get PathInfo from request
getRawPathInfo()  : string
Get raw PathInfo from request (not urldecoded)
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.
getRequestUri()  : string
Returns the request uri, even if the website uses one or more reverse proxies
getScriptName()  : string
Returns the script name, even if the website uses one or more reverse proxies
getServerHost()  : string
Returns the server host from the headers, or the first configured trusted domain if the host isn't in the trusted list
getServerProtocol()  : string
Returns the server protocol. It respects reverse proxy servers and load balancers.
getUploadedFile()  : array<string|int, mixed>
Shortcut for accessing an uploaded file through the $_FILES array
isUserAgent()  : bool
Checks whether the user agent matches a given regex
passesCSRFCheck()  : bool
Checks if the CSRF check was correct
passesLaxCookieCheck()  : bool
Checks if the lax cookie has been sent with the request if the request is including any cookies.
passesStrictCookieCheck()  : bool
Checks if the strict cookie has been sent with the request if the request is including any cookies.

Constants

JSON_CONTENT_TYPE_REGEX

public mixed JSON_CONTENT_TYPE_REGEX = '/^application\/(?:[a-z0-9.-]+\+)?json\b/'
Tags
since
26.0.0

USER_AGENT_CLIENT_ANDROID

public mixed USER_AGENT_CLIENT_ANDROID = '/^Mozilla\/5\.0 \(Android\) (?:ownCloud|Nextcloud)\-android\/([^ ]*).*$/'
Tags
since
9.1.0
since
28.0.0

The regex has a group matching the version number

USER_AGENT_CLIENT_DESKTOP

public mixed USER_AGENT_CLIENT_DESKTOP = '/^Mozilla\/5\.0 \([A-Za-z ]+\) (?:mirall|csyncoC)\/([^ ]*).*$/'
Tags
since
9.1.0
since
28.0.0

The regex has a group matching the version number

USER_AGENT_CLIENT_IOS

public mixed USER_AGENT_CLIENT_IOS = '/^Mozilla\/5\.0 \(iOS\) (?:ownCloud|Nextcloud)\-iOS\/([^ ]*).*$/'
Tags
since
9.1.0
since
28.0.0

The regex has a group matching the version number

USER_AGENT_OUTLOOK_ADDON

public mixed USER_AGENT_OUTLOOK_ADDON = '/^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Outlook v([^ ]*).*$/'
Tags
since
13.0.1
since
28.0.0

The regex has a group matching the version number

USER_AGENT_TALK_ANDROID

public mixed USER_AGENT_TALK_ANDROID = '/^Mozilla\/5\.0 \(Android\) Nextcloud\-Talk v([^ ]*).*$/'
Tags
since
13.0.0
since
28.0.0

The regex has a group matching the version number

USER_AGENT_TALK_DESKTOP

public mixed USER_AGENT_TALK_DESKTOP = '/^Mozilla\/5\.0 \((?!Android|iOS)[A-Za-z ]+\) Nextcloud\-Talk v([^ ]*).*$/'
Tags
since
26.0.0
since
28.0.0

The regex has a group matching the version number

USER_AGENT_TALK_IOS

public mixed USER_AGENT_TALK_IOS = '/^Mozilla\/5\.0 \(iOS\) Nextcloud\-Talk v([^ ]*).*$/'
Tags
since
13.0.0
since
28.0.0

The regex has a group matching the version number

USER_AGENT_THUNDERBIRD_ADDON

public mixed USER_AGENT_THUNDERBIRD_ADDON = '/^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Thunderbird v([^ ]*).*$/'
Tags
since
13.0.1
since
28.0.0

The regex has a group matching the version number

Methods

getCookie()

Shortcut for getting cookie variables

public getCookie(string $key) : string|null
Parameters
$key : string

the key that will be taken from the $_COOKIE array

Tags
psalm-taint-source

input

since
6.0.0
Return values
string|null

the value in the $_COOKIE element

getEnv()

Shortcut for getting env variables

public getEnv(string $key) : array<string|int, mixed>
Parameters
$key : string

the key that will be taken from the $_ENV array

Tags
since
6.0.0
Return values
array<string|int, mixed>

the value in the $_ENV element

getHeader()

public getHeader(string $name) : string
Parameters
$name : string
Tags
psalm-taint-source

input

since
6.0.0
Return values
string

getHttpProtocol()

Returns the used HTTP protocol.

public getHttpProtocol() : string
Tags
since
8.2.0
Return values
string

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

getId()

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.

public getId() : string
Tags
since
8.1.0
Return values
string

getInsecureServerHost()

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

public getInsecureServerHost() : string
Tags
psalm-taint-source

input

since
8.1.0
Return values
string

Server host

getMethod()

Returns the method of the request

public getMethod() : string
Tags
since
6.0.0
Return values
string

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

getParam()

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

public getParam(string $key[, mixed $default = null ]) : mixed
Parameters
$key : string

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
$default : mixed = null

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

Tags
psalm-taint-source

input

since
6.0.0
Return values
mixed

the content of the array

getParams()

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

public getParams() : array<string|int, mixed>

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

Tags
psalm-taint-source

input

since
6.0.0
Return values
array<string|int, mixed>

the array with all parameters

getPathInfo()

Get PathInfo from request

public getPathInfo() : string|false
Tags
psalm-taint-source

input

throws
Exception
since
8.1.0
Return values
string|false

Path info or false when not found

getRawPathInfo()

Get raw PathInfo from request (not urldecoded)

public getRawPathInfo() : string
Tags
psalm-taint-source

input

throws
Exception
since
8.1.0
Return values
string

Path info

getRemoteAddress()

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.

public getRemoteAddress() : string

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

Tags
since
8.1.0
Return values
string

IP address

getRequestUri()

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

public getRequestUri() : string
Tags
psalm-taint-source

input

since
8.1.0
Return values
string

getScriptName()

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

public getScriptName() : string
Tags
since
8.1.0
Return values
string

the script name

getServerHost()

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

public getServerHost() : string
Tags
since
8.1.0
Return values
string

Server host

getServerProtocol()

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

public getServerProtocol() : string
Tags
since
8.1.0
Return values
string

Server protocol (http or https)

getUploadedFile()

Shortcut for accessing an uploaded file through the $_FILES array

public getUploadedFile(string $key) : array<string|int, mixed>
Parameters
$key : string

the key that will be taken from the $_FILES array

Tags
since
6.0.0
Return values
array<string|int, mixed>

the file in the $_FILES element

isUserAgent()

Checks whether the user agent matches a given regex

public isUserAgent(array<string|int, mixed> $agent) : bool
Parameters
$agent : array<string|int, mixed>

array of agent names

Tags
since
8.1.0
Return values
bool

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

passesCSRFCheck()

Checks if the CSRF check was correct

public passesCSRFCheck() : bool
Tags
since
6.0.0
Return values
bool

true if CSRF check passed

passesLaxCookieCheck()

Checks if the lax cookie has been sent with the request if the request is including any cookies.

public passesLaxCookieCheck() : bool
Tags
since
9.0.0
Return values
bool

passesStrictCookieCheck()

Checks if the strict cookie has been sent with the request if the request is including any cookies.

public passesStrictCookieCheck() : bool
Tags
since
9.0.0
Return values
bool

        
On this page

Search results