Nextcloud PHP API (master)

TemplateResponse extends Response
in package

Response for a normal template

Tags
since
6.0.0
template

S of int

template

H of array<string, mixed>

template-extends

Response<int, array<string, mixed>>

Table of Contents

Constants

RENDER_AS_BASE  = 'base'
RENDER_AS_BLANK  = ''
RENDER_AS_ERROR  = 'error'
RENDER_AS_GUEST  = 'guest'
RENDER_AS_PUBLIC  = 'public'
RENDER_AS_USER  = 'user'

Properties

$appName  : string
app name
$params  : array<string|int, mixed>
parameters
$renderAs  : string
rendering type (admin, user, blank)
$templateName  : string
name of the template
$contentSecurityPolicy  : ContentSecurityPolicy|null
$cookies  : array<string|int, mixed>
Cookies that will be need to be constructed as header
$ETag  : string
ETag
$featurePolicy  : FeaturePolicy
$headers  : H
Headers
$lastModified  : DateTime
Last modified date
$status  : S
HTTP status code - defaults to STATUS OK
$throttled  : bool
$throttleMetadata  : array<string|int, mixed>

Methods

__construct()  : mixed
constructor of TemplateResponse
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
getApp()  : string
getContentSecurityPolicy()  : EmptyContentSecurityPolicy|null
Get the currently used Content-Security-Policy
getCookies()  : array<string|int, mixed>
Returns the cookies
getETag()  : string
Get the ETag
getFeaturePolicy()  : EmptyFeaturePolicy
getHeaders()  : mixed
Returns the set headers
getLastModified()  : DateTime
Get "last modified" date
getParams()  : array<string|int, mixed>
Used for accessing the set parameters
getRenderAs()  : string
Returns the set renderAs
getStatus()  : S
Get response status
getTemplateName()  : string
Used for accessing the name of the set template
getThrottleMetadata()  : array<string|int, mixed>
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
Returns the rendered html
renderAs()  : TemplateResponse
Sets the template page
setContentSecurityPolicy()  : $this
Set a Content-Security-Policy
setCookies()  : $this
Set the specified cookies
setETag()  : Response
Set the ETag
setFeaturePolicy()  : self
setHeaders()  : static
Set the headers
setLastModified()  : Response
Set "last modified" date
setParams()  : TemplateResponse
Sets template parameters
setStatus()  : static
Set response status
throttle()  : mixed
Marks the response as to throttle. Will be throttled when the

Constants

RENDER_AS_ERROR

public mixed RENDER_AS_ERROR = 'error'
Tags
since
20.0.0

RENDER_AS_GUEST

public mixed RENDER_AS_GUEST = 'guest'
Tags
since
20.0.0

RENDER_AS_PUBLIC

public mixed RENDER_AS_PUBLIC = 'public'
Tags
since
20.0.0

Properties

$renderAs

rendering type (admin, user, blank)

protected string $renderAs

$cookies

Cookies that will be need to be constructed as header

private array<string|int, mixed> $cookies = []

$lastModified

Last modified date

private DateTime $lastModified

$status

HTTP status code - defaults to STATUS OK

private S $status

$throttled

private bool $throttled = false

$throttleMetadata

private array<string|int, mixed> $throttleMetadata = []

Methods

__construct()

constructor of TemplateResponse

public __construct(string $appName, string $templateName[, array<string|int, mixed> $params = [] ][, string $renderAs = self::RENDER_AS_USER ][, S $status = Http::STATUS_OK ][, H $headers = [] ]) : mixed
Parameters
$appName : string

the name of the app to load the template from

$templateName : string

the name of the template

$params : array<string|int, mixed> = []

an array of parameters which should be passed to the template

$renderAs : string = self::RENDER_AS_USER

how the page should be rendered, defaults to user

$status : S = Http::STATUS_OK
$headers : H = []
Tags
since
6.0.0
  • parameters $params and $renderAs were added in 7.0.0

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 ][, bool $immutable = false ]) : $this
Parameters
$cacheSeconds : int

amount of seconds the response is fresh, 0 to disable cache.

$public : bool = false

whether the page should be cached by public proxy. Usually should be false, unless this is a static resources.

$immutable : bool = false

whether browser should treat the resource as immutable and not ask the server for each page load if the resource changed.

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

getApp()

public getApp() : string
Tags
since
25.0.0
Return values
string

the app id of the used template

getCookies()

Returns the cookies

public getCookies() : array<string|int, mixed>
Tags
since
8.0.0
Return values
array<string|int, mixed>

getETag()

Get the ETag

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

the etag

getHeaders()

Returns the set headers

public getHeaders() : mixed
Tags
@return

array{X-Request-Id: string, Cache-Control: string, Content-Security-Policy: string, Feature-Policy: string, X-Robots-Tag: string, Last-Modified?: string, ETag?: string, ...H} the headers

since
6.0.0

getLastModified()

Get "last modified" date

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

RFC2822 formatted last modified date

getParams()

Used for accessing the set parameters

public getParams() : array<string|int, mixed>
Tags
since
6.0.0
Return values
array<string|int, mixed>

the params

getRenderAs()

Returns the set renderAs

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

the renderAs value

getStatus()

Get response status

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

getTemplateName()

Used for accessing the name of the set template

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

the name of the used template

getThrottleMetadata()

Returns the throttle metadata, defaults to empty array

public getThrottleMetadata() : array<string|int, mixed>
Tags
since
13.0.0
Return values
array<string|int, mixed>

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<string|int, mixed> $cookieNames) : $this
Parameters
$cookieNames : array<string|int, mixed>

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

render()

Returns the rendered html

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

the rendered html

renderAs()

Sets the template page

public renderAs(string $renderAs) : TemplateResponse
Parameters
$renderAs : string

admin, user or blank. Admin also prints the admin settings header and footer, user renders the normal normal page including footer and header and blank just renders the plain template

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

Reference to this object

setCookies()

Set the specified cookies

public setCookies(array<string|int, mixed> $cookies) : $this
Parameters
$cookies : array<string|int, mixed>

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(NewH $headers) : static
Parameters
$headers : NewH

value header pairs

Tags
template

NewH as array<string, mixed>

psalm-this-out

static<S, NewH>

since
8.0.0
Return values
static

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

setParams()

Sets template parameters

public setParams(array<string|int, mixed> $params) : TemplateResponse
Parameters
$params : array<string|int, mixed>

an array with key => value structure which sets template variables

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

Reference to this object

setStatus()

Set response status

public setStatus(NewS $status) : static
Parameters
$status : NewS

a HTTP status code, see also the STATUS constants

Tags
template

NewS as int

psalm-this-out

static<NewS, H>

since
6.0.0
  • return value was added in 7.0.0
Return values
static

throttle()

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

public throttle([array<string|int, mixed> $metadata = [] ]) : mixed
Parameters
$metadata : array<string|int, mixed> = []
Tags
BruteForceProtection

annotation is added.

since
12.0.0

        
On this page

Search results