DataResponse
extends Response
in package
A generic DataResponse class that is used to return generic data responses for responders to transform
Tags
Table of Contents
Properties
- $data : T
- response data
- $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
- 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<string|int, mixed>
- Returns the cookies
- getData() : T
- Used to get the set parameters
- getETag() : string
- Get the ETag
- getFeaturePolicy() : EmptyFeaturePolicy
- getHeaders() : mixed
- Returns the set headers
- getLastModified() : DateTime
- Get "last modified" date
- getStatus() : S
- Get response status
- 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
- 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() : static
- Set the headers
- setLastModified() : Response
- Set "last modified" date
- setStatus() : static
- Set response status
- throttle() : mixed
- Marks the response as to throttle. Will be throttled when the
Properties
$data
response data
protected
T
$data
$contentSecurityPolicy
private
ContentSecurityPolicy|null
$contentSecurityPolicy
= null
Used Content-Security-Policy
$cookies
Cookies that will be need to be constructed as header
private
array<string|int, mixed>
$cookies
= []
$ETag
ETag
private
string
$ETag
$featurePolicy
private
FeaturePolicy
$featurePolicy
$headers
Headers
private
H
$headers
$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()
public
__construct([T $data = [] ][, S $statusCode = Http::STATUS_OK ][, H $headers = [] ]) : mixed
Parameters
- $data : T = []
-
the object or array that should be transformed
- $statusCode : S = Http::STATUS_OK
-
the Http status code, defaults to 200
- $headers : H = []
-
additional key value based headers
Tags
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
Return values
$thisaddHeader()
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
Return values
$thiscacheFor()
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
Return values
$thisgetContentSecurityPolicy()
Get the currently used Content-Security-Policy
public
getContentSecurityPolicy() : EmptyContentSecurityPolicy|null
Tags
Return values
EmptyContentSecurityPolicy|null —Used Content-Security-Policy or null if none specified.
getCookies()
Returns the cookies
public
getCookies() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>getData()
Used to get the set parameters
public
getData() : T
Tags
Return values
T —the data
getETag()
Get the ETag
public
getETag() : string
Tags
Return values
string —the etag
getFeaturePolicy()
public
getFeaturePolicy() : EmptyFeaturePolicy
Tags
Return values
EmptyFeaturePolicygetHeaders()
Returns the set headers
public
getHeaders() : mixed
Tags
getLastModified()
Get "last modified" date
public
getLastModified() : DateTime
Tags
Return values
DateTime —RFC2822 formatted last modified date
getStatus()
Get response status
public
getStatus() : S
Tags
Return values
SgetThrottleMetadata()
Returns the throttle metadata, defaults to empty array
public
getThrottleMetadata() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>invalidateCookie()
Invalidates the specified cookie
public
invalidateCookie(string $name) : $this
Parameters
- $name : string
Tags
Return values
$thisinvalidateCookies()
Invalidates the specified cookies
public
invalidateCookies(array<string|int, mixed> $cookieNames) : $this
Parameters
- $cookieNames : array<string|int, mixed>
-
array('foo', 'bar')
Tags
Return values
$thisisThrottled()
Whether the current response is throttled.
public
isThrottled() : mixed
Tags
render()
By default renders no output
public
render() : string
Tags
Return values
stringsetContentSecurityPolicy()
Set a Content-Security-Policy
public
setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) : $this
Parameters
- $csp : EmptyContentSecurityPolicy
-
Policy to set for the response object
Tags
Return values
$thissetCookies()
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
Return values
$thissetData()
Sets values in the data json array
public
setData(T $data) : DataResponse
Parameters
- $data : T
-
an array or object which will be transformed
Tags
Return values
DataResponse —Reference to this object
setETag()
Set the ETag
public
setETag(string $ETag) : Response
Parameters
- $ETag : string
Tags
Return values
Response —Reference to this object
setFeaturePolicy()
public
setFeaturePolicy(EmptyFeaturePolicy $featurePolicy) : self
Parameters
- $featurePolicy : EmptyFeaturePolicy
Tags
Return values
selfsetHeaders()
Set the headers
public
setHeaders(NewH $headers) : static
Parameters
- $headers : NewH
-
value header pairs
Tags
Return values
staticsetLastModified()
Set "last modified" date
public
setLastModified(DateTime $lastModified) : Response
Parameters
- $lastModified : DateTime
Tags
Return values
Response —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
Return values
staticthrottle()
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> = []