ResponseFormatterTrait
VuFind Action Feature Trait - HTTP response formatting support methods
Tags
Table of Contents
- addCorsHeaders() : void
- Add CORS headers to a response.
- getJsonResponse() : Response
- Get a JSON response from an array of data
Methods
addCorsHeaders()
Add CORS headers to a response.
protected
addCorsHeaders(Response $response[, array<string|int, mixed> $allowedMethods = ['GET', 'POST', 'OPTIONS'] ][, array<string|int, mixed> $allowedHeaders = [] ][, string $allowedOrigin = '*' ][, bool $allowCredentials = false ][, int $maxAge = 86400 ]) : void
Parameters
- $response : Response
-
Response
- $allowedMethods : array<string|int, mixed> = ['GET', 'POST', 'OPTIONS']
-
Allowed HTTP methods
- $allowedHeaders : array<string|int, mixed> = []
-
Allowed HTTP headers
- $allowedOrigin : string = '*'
-
Allowed origin (see https://developer.mozilla.org/ en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin for details)
- $allowCredentials : bool = false
-
Whether credentials are allowed
- $maxAge : int = 86400
-
Maximum time in seconds the information from a preflight request can be cached
Return values
void —getJsonResponse()
Get a JSON response from an array of data
protected
getJsonResponse(array<string|int, mixed> $data[, int $statusCode = 200 ]) : Response
Parameters
- $data : array<string|int, mixed>
-
Data to encode
- $statusCode : int = 200
-
HTTP status code