Rescuer
A pretty basic contingency plan.
Under normal circumstances, this class will simply return the response given
by the $next function. In the event that an Exception occurred in the
$next function, this class will craft a new response containing details
about the error itself.
- Copyright
- 2015-2016 Appertly
- License
- Apache-2.0
Instance Properties
| Name | Type | Summary |
|---|---|---|
$debug | bool | Whether to include exception information in responses |
$xhpClass | string | The class name of the XHP to render |
Static Properties
| Name | Type | Summary |
|---|---|---|
$messages | ImmMap<int,string> | Convenient map of HTTP status codes to human-readable explanations |
Constructors / Destructors
| Returns | Signature and Description |
|---|---|
void | __construct()Creates a new Contingency. |
Instance Methods
| Returns | Signature and Description |
|---|---|
ResponseInterface | __invoke(, , )Middleware request–response handling. |
int | Gets the plugin priority; larger means first. |
ResponseInterface | process(, , )Handles an exception. |
| Returns | Signature and Description |
|---|---|
Map<string,mixed> | getValues(, )Assembles the values from the Request and Exception. |
XHPRoot | renderHtml()Returns the XHP to render. |
ProblemDetails | renderJson()Returns the ProblemDetails to render. |
Property Details
$debug
bool $debugWhether to include exception information in responses
$messages
ImmMap<int,string> $messagesConvenient map of HTTP status codes to human-readable explanations
$xhpClass
string $xhpClassThe class name of the XHP to render
Method Details
__construct
__construct(ConstMap<string,mixed> $options = ImmMap{})Creates a new Contingency.
The following options are available:
debug– Whether to include exception stack trace information (should befalsein production!). Defaults tofalse.xhpClass– The class name of XHP to render (must bexhp_class_nameformat). Defaults toxhp__labrys__error_page.
| Name | Type | Description |
|---|---|---|
$options | ConstMap<string,mixed> | The options |
__invoke
__invoke(ServerRequestInterface $request, ResponseInterface $response, (function(Request,Response):Response) $next)Middleware request–response handling.
| Name | Type | Description |
|---|---|---|
$request | ServerRequestInterface | The server request |
$response | ResponseInterface | The response |
$next | (function(Request,Response):Response) |
| Type | Description |
|---|---|
ResponseInterface | The response |
getPriority
getPriority()Gets the plugin priority; larger means first.
| Type | Description |
|---|---|
int | The plugin priority |
getValues
getValues(ServerRequestInterface $request, Exception $e)Assembles the values from the Request and Exception.
| Name | Type | Description |
|---|---|---|
$request | ServerRequestInterface | The request |
$e | Exception | The Exception |
| Type | Description |
|---|---|
Map<string,mixed> | The assembled values |
process
process(ServerRequestInterface $request, ResponseInterface $response, Exception $e)Handles an exception.
This is your chance for logging, changing the HTTP status header, and rendering some kind of message for the client.
| Name | Type | Description |
|---|---|---|
$request | ServerRequestInterface | The request |
$response | ResponseInterface | The response |
$e | Exception | The exception to process |
| Type | Description |
|---|---|
ResponseInterface | The new response |
renderHtml
renderHtml(Map<string,mixed> $values)Returns the XHP to render.
| Name | Type | Description |
|---|---|---|
$values | Map<string,mixed> | The values |
| Type | Description |
|---|---|
XHPRoot | The HTML response |
renderJson
renderJson(Map<string,mixed> $values)Returns the ProblemDetails to render.
| Name | Type | Description |
|---|---|---|
$values | Map<string,mixed> | The values |
| Type | Description |
|---|---|
ProblemDetails | The JSON response |