Nextcloud PHP API (stable18)

DataResponse extends Response

A generic DataResponse class that is used to return generic data responses for responders to transform

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

Tags
since
8.0.0

Table of Contents

$data  : array|object
response data
$contentSecurityPolicy  : ContentSecurityPolicy|null
$cookies  : array
Cookies that will be need to be constructed as header
$ETag  : string
ETag
$featurePolicy  : FeaturePolicy
$headers  : array
Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate']
$lastModified  : DateTime
Last modified date
$status  : int
HTTP status code - defaults to STATUS OK
$throttled  : bool
$throttleMetadata  : array
__construct()  : mixed
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
getData()  : array
Used to get the set parameters
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
setData()  : DataResponse
Sets values in the data json array
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 = array()

$headers

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

private array $headers = array('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()

public __construct([array|object $data = array() ][, int $statusCode = Http::STATUS_OK ][, array $headers = array() ]) : mixed
Parameters
$data : array|object = array()

the object or array that should be transformed

$statusCode : int = Http::STATUS_OK

the Http status code, defaults to 200

$headers : array = array()

additional key value based headers

Tags
since
8.0.0
Return values
mixed

addCookie()

Adds a new cookie to the response

public addCookie(string $name, string $value[, DateTime|null $expireDate = null ]) : $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.

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) : $this
Parameters
$cacheSeconds : int

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

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

getData()

Used to get the set parameters

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

the data

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
6.0.0
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

setData()

Sets values in the data json array

public setData(array|object $data) : DataResponse
Parameters
$data : array|object

an array or object which will be transformed

Tags
since
8.0.0
Return values
DataResponse

Reference to this object

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