Nextcloud PHP API (stable19)

OCSResponse extends Response

A renderer for OCS responses

It handles headers, HTTP status code, last modified and ETag.

Tags
since
8.1.0
deprecated
9.2.0

To implement an OCS endpoint extend the OCSController

Table of Contents

$contentSecurityPolicy  : ContentSecurityPolicy|null
$cookies  : array
Cookies that will be need to be constructed as header
$data  : mixed
$ETag  : string
ETag
$featurePolicy  : FeaturePolicy
$format  : mixed
$headers  : array
Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate']
$itemscount  : mixed
$itemsperpage  : mixed
$lastModified  : DateTime
Last modified date
$message  : mixed
$status  : int
HTTP status code - defaults to STATUS OK
$statuscode  : mixed
$throttled  : bool
$throttleMetadata  : array
__construct()  : mixed
generates the xml or json response for the API call from an multidimenional data array.
addCookie()  : $this
Adds a new cookie to the response
addHeader()  : $this
Adds a new header to the response that will be called before the render function
cacheFor()  : $this
Caches the response
getContentSecurityPolicy()  : EmptyContentSecurityPolicy|null
Get the currently used Content-Security-Policy
getCookies()  : array
Returns the cookies
getETag()  : string
Get the ETag
getFeaturePolicy()  : EmptyFeaturePolicy
getHeaders()  : array
Returns the set headers
getLastModified()  : DateTime
Get "last modified" date
getStatus()  : mixed
Get response status
getThrottleMetadata()  : array
Returns the throttle metadata, defaults to empty array
invalidateCookie()  : $this
Invalidates the specified cookie
invalidateCookies()  : $this
Invalidates the specified cookies
isThrottled()  : mixed
Whether the current response is throttled.
render()  : string
By default renders no output
setContentSecurityPolicy()  : $this
Set a Content-Security-Policy
setCookies()  : $this
Set the specified cookies
setETag()  : Response
Set the ETag
setFeaturePolicy()  : self
setHeaders()  : $this
Set the headers
setLastModified()  : Response
Set "last modified" date
setStatus()  : Response
Set response status
throttle()  : mixed
Marks the response as to throttle. Will be throttled when the

Properties

$cookies

Cookies that will be need to be constructed as header

private array $cookies = []

$headers

Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate']

private array $headers = ['Cache-Control' => 'no-cache, no-store, must-revalidate']

$lastModified

Last modified date

private DateTime $lastModified

$status

HTTP status code - defaults to STATUS OK

private int $status = OCPAppFrameworkHttp::STATUS_OK

$throttled

private bool $throttled = false

$throttleMetadata

private array $throttleMetadata = []

Methods

__construct()

generates the xml or json response for the API call from an multidimenional data array.

public __construct(string $format, int $statuscode, string $message[, array $data = [] ][, int|string $itemscount = '' ][, int|string $itemsperpage = '' ]) : mixed
Parameters
$format : string
$statuscode : int
$message : string
$data : array = []
$itemscount : int|string = ''
$itemsperpage : int|string = ''
Tags
since
8.1.0
deprecated
9.2.0

To implement an OCS endpoint extend the OCSController

Return values
mixed

addCookie()

Adds a new cookie to the response

public addCookie(string $name, string $value[, DateTime|null $expireDate = null ][, string $sameSite = 'Lax' ]) : $this
Parameters
$name : string

The name of the cookie

$value : string

The value of the cookie

$expireDate : DateTime|null = null

Date on that the cookie should expire, if set to null cookie will be considered as session cookie.

$sameSite : string = 'Lax'

The samesite value of the cookie. Defaults to Lax. Other possibilities are Strict or None

Tags
since
8.0.0
Return values
$this

addHeader()

Adds a new header to the response that will be called before the render function

public addHeader(string $name, string $value) : $this
Parameters
$name : string

The name of the HTTP header

$value : string

The value, null will delete it

Tags
since
6.0.0
  • return value was added in 7.0.0
Return values
$this

cacheFor()

Caches the response

public cacheFor(int $cacheSeconds[, bool $public = false ]) : $this
Parameters
$cacheSeconds : int

the amount of seconds that should be cached if 0 then caching will be disabled

$public : bool = false
Tags
since
6.0.0
  • return value was added in 7.0.0
Return values
$this

getCookies()

Returns the cookies

public getCookies() : array
Tags
since
8.0.0
Return values
array

getETag()

Get the ETag

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

the etag

getHeaders()

Returns the set headers

public getHeaders() : array
Tags
since
6.0.0
Return values
array

the headers

getLastModified()

Get "last modified" date

public getLastModified() : DateTime
Tags
since
6.0.0
Return values
DateTime

RFC2822 formatted last modified date

getStatus()

Get response status

public getStatus() : mixed
Tags
since
6.0.0
Return values
mixed

getThrottleMetadata()

Returns the throttle metadata, defaults to empty array

public getThrottleMetadata() : array
Tags
since
13.0.0
Return values
array

invalidateCookie()

Invalidates the specified cookie

public invalidateCookie(string $name) : $this
Parameters
$name : string
Tags
since
8.0.0
Return values
$this

invalidateCookies()

Invalidates the specified cookies

public invalidateCookies(array $cookieNames) : $this
Parameters
$cookieNames : array

array('foo', 'bar')

Tags
since
8.0.0
Return values
$this

isThrottled()

Whether the current response is throttled.

public isThrottled() : mixed
Tags
since
12.0.0
Return values
mixed

render()

By default renders no output

public render() : string
Tags
since
8.1.0
deprecated
9.2.0

To implement an OCS endpoint extend the OCSController

suppress

PhanDeprecatedClass

Return values
string

setCookies()

Set the specified cookies

public setCookies(array $cookies) : $this
Parameters
$cookies : array

array('foo' => array('value' => 'bar', 'expire' => null))

Tags
since
8.0.0
Return values
$this

setETag()

Set the ETag

public setETag(string $ETag) : Response
Parameters
$ETag : string
Tags
since
6.0.0
  • return value was added in 7.0.0
Return values
Response

Reference to this object

setHeaders()

Set the headers

public setHeaders(array $headers) : $this
Parameters
$headers : array

value header pairs

Tags
since
8.0.0
Return values
$this

setLastModified()

Set "last modified" date

public setLastModified(DateTime $lastModified) : Response
Parameters
$lastModified : DateTime
Tags
since
6.0.0
  • return value was added in 7.0.0
Return values
Response

Reference to this object

setStatus()

Set response status

public setStatus(int $status) : Response
Parameters
$status : int

a HTTP status code, see also the STATUS constants

Tags
since
6.0.0
  • return value was added in 7.0.0
Return values
Response

Reference to this object

throttle()

Marks the response as to throttle. Will be throttled when the

public throttle([array $metadata = [] ]) : mixed
Parameters
$metadata : array = []
Tags
BruteForceProtection

annotation is added.

since
12.0.0
Return values
mixed

Search results