\OCP\AppFramework\HttpOCSResponse

A renderer for OCS responses

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

Summary

Methods
Properties
Constants
cacheFor()
addCookie()
setCookies()
invalidateCookie()
invalidateCookies()
getCookies()
addHeader()
setHeaders()
getHeaders()
render()
setStatus()
setContentSecurityPolicy()
getContentSecurityPolicy()
getStatus()
getETag()
getLastModified()
setETag()
setLastModified()
__construct()
getStatusCode()
setStatusCode()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$headers
$cookies
$status
$lastModified
$ETag
$contentSecurityPolicy
$data
$format
$statuscode
$message
$itemscount
$itemsperpage
N/A

Properties

$headers

$headers : array

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

Type

array

$cookies

$cookies : array

Cookies that will be need to be constructed as header

Type

array

$status

$status : integer

HTTP status code - defaults to STATUS OK

Type

integer

$lastModified

$lastModified : \DateTime

Last modified date

Type

\DateTime

$ETag

$ETag : string

ETag

Type

string

$data

$data : 

Type

$format

$format : 

Type

$statuscode

$statuscode : 

Type

$message

$message : 

Type

$itemscount

$itemscount : 

Type

$itemsperpage

$itemsperpage : 

Type

Methods

cacheFor()

cacheFor(integer  $cacheSeconds) : $this

Caches the response

Parameters

integer $cacheSeconds

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

Returns

$this

addCookie()

addCookie(string  $name, string  $value, \DateTime|null  $expireDate = null) : $this

Adds a new cookie to the response

Parameters

string $name

The name of the cookie

string $value

The value of the cookie

\DateTime|null $expireDate

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

Returns

$this

setCookies()

setCookies(array  $cookies) : $this

Set the specified cookies

Parameters

array $cookies

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

Returns

$this

invalidateCookie()

invalidateCookie(string  $name) : $this

Invalidates the specified cookie

Parameters

string $name

Returns

$this

invalidateCookies()

invalidateCookies(array  $cookieNames) : $this

Invalidates the specified cookies

Parameters

array $cookieNames

array('foo', 'bar')

Returns

$this

getCookies()

getCookies() : array

Returns the cookies

Returns

array

addHeader()

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

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

Parameters

string $name

The name of the HTTP header

string $value

The value, null will delete it

Returns

$this

setHeaders()

setHeaders(array  $headers) : $this

Set the headers

Parameters

array $headers

value header pairs

Returns

$this

getHeaders()

getHeaders() : array

Returns the set headers

Returns

array —

the headers

render()

render() : string

By default renders no output

Returns

string

setStatus()

setStatus(integer  $status) : \OCP\AppFramework\Http\Response

Set response status

Parameters

integer $status

a HTTP status code, see also the STATUS constants

Returns

\OCP\AppFramework\Http\Response

Reference to this object

setContentSecurityPolicy()

setContentSecurityPolicy(\OCP\AppFramework\Http\ContentSecurityPolicy  $csp) : $this

Set a Content-Security-Policy

Parameters

\OCP\AppFramework\Http\ContentSecurityPolicy $csp

Policy to set for the response object

Returns

$this

getContentSecurityPolicy()

getContentSecurityPolicy() : \OCP\AppFramework\Http\ContentSecurityPolicy|null

Get the currently used Content-Security-Policy

Returns

\OCP\AppFramework\Http\ContentSecurityPolicy|null —

Used Content-Security-Policy or null if none specified.

getStatus()

getStatus() 

Get response status

getETag()

getETag() : string

Get the ETag

Returns

string —

the etag

getLastModified()

getLastModified() : \DateTime

Get "last modified" date

Returns

\DateTime —

RFC2822 formatted last modified date

setETag()

setETag(string  $ETag) : \OCP\AppFramework\Http\Response

Set the ETag

Parameters

string $ETag

Returns

\OCP\AppFramework\Http\Response

Reference to this object

setLastModified()

setLastModified(\DateTime  $lastModified) : \OCP\AppFramework\Http\Response

Set "last modified" date

Parameters

\DateTime $lastModified

Returns

\OCP\AppFramework\Http\Response

Reference to this object

__construct()

__construct(string  $format, integer  $statuscode, string  $message, array  $data = array(), integer|string  $itemscount = '', integer|string  $itemsperpage = '') 

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

Parameters

string $format
integer $statuscode
string $message
array $data
integer|string $itemscount
integer|string $itemsperpage

getStatusCode()

getStatusCode() : integer

Returns

integer

setStatusCode()

setStatusCode(integer  $statuscode) 

Parameters

integer $statuscode