Responder
in package
A generic responder.
Table of Contents
Properties
- $phpRenderer : PhpRenderer
- $responseFactory : ResponseFactoryInterface
- $routeParser : RouteParserInterface
Methods
- __construct() : mixed
- The constructor.
- createResponse() : ResponseInterface
- Create a new response.
- withHeader() : mixed
- withJson() : ResponseInterface
- Write JSON to the response body.
- withRedirect() : ResponseInterface
- Creates a redirect for the given url / route name.
- withRedirectFor() : ResponseInterface
- Creates a redirect for the given url / route name.
- withTemplate() : ResponseInterface
- Output rendered template.
Properties
$phpRenderer
private
PhpRenderer
$phpRenderer
$responseFactory
private
ResponseFactoryInterface
$responseFactory
$routeParser
private
RouteParserInterface
$routeParser
Methods
__construct()
The constructor.
public
__construct(PhpRenderer $phpRenderer, RouteParserInterface $routeParser, ResponseFactoryInterface $responseFactory) : mixed
Parameters
- $phpRenderer : PhpRenderer
-
The template engine
- $routeParser : RouteParserInterface
-
The route parser
- $responseFactory : ResponseFactoryInterface
-
The response factory
createResponse()
Create a new response.
public
createResponse() : ResponseInterface
Return values
ResponseInterface —The response
withHeader()
public
withHeader(string $string, string $string1) : mixed
Parameters
- $string : string
- $string1 : string
withJson()
Write JSON to the response body.
public
withJson(ResponseInterface $response[, mixed $data = null ][, int $options = 0 ]) : ResponseInterface
This method prepares the response object to return an HTTP JSON response to the client.
Parameters
- $response : ResponseInterface
-
The response
- $data : mixed = null
-
The data
- $options : int = 0
-
Json encoding options
Return values
ResponseInterface —The response
withRedirect()
Creates a redirect for the given url / route name.
public
withRedirect(ResponseInterface $response, string $destination[, array<string|int, mixed> $queryParams = [] ]) : ResponseInterface
This method prepares the response object to return an HTTP Redirect response to the client.
Parameters
- $response : ResponseInterface
-
The response
- $destination : string
-
The redirect destination (url or route name)
- $queryParams : array<string|int, mixed> = []
-
Optional query string parameters
Return values
ResponseInterface —The response
withRedirectFor()
Creates a redirect for the given url / route name.
public
withRedirectFor(ResponseInterface $response, string $routeName[, array<string|int, mixed> $data = [] ][, array<string|int, mixed> $queryParams = [] ]) : ResponseInterface
This method prepares the response object to return an HTTP Redirect response to the client.
Parameters
- $response : ResponseInterface
-
The response
- $routeName : string
-
The redirect route name
- $data : array<string|int, mixed> = []
-
Named argument replacement data
- $queryParams : array<string|int, mixed> = []
-
Optional query string parameters
Return values
ResponseInterface —The response
withTemplate()
Output rendered template.
public
withTemplate(ResponseInterface $response, string $template[, array<string|int, mixed> $data = [] ]) : ResponseInterface
Parameters
- $response : ResponseInterface
-
The response
- $template : string
-
Template pathname relative to templates directory
- $data : array<string|int, mixed> = []
-
Associative array of template variables
Return values
ResponseInterface —The response