ExceptionHandler implements ExceptionHandlerInterface Uses DeterminesContentType
Generic handler for exceptions.
Tags
Table of Contents
$ci | ContainerInterface | |
---|---|---|
$request | ServerRequestInterface | |
$response | ResponseInterface | |
$exception | Throwable | |
$renderer | ErrorRendererInterface | |
$contentType | string | |
$statusCode | int | |
$displayErrorDetails | Tells the handler whether or not to output detailed error information to the client. | bool |
$knownContentTypes | Known handled content types. | array |
__construct() | Create a new ExceptionHandler object. | mixed |
handle() | Handle the caught exception. | ResponseInterface |
renderDebugResponse() | Render a detailed response with debugging information. | ResponseInterface |
renderGenericResponse() | Render a generic, user-friendly response without sensitive debugging information. | ResponseInterface |
writeToErrorLog() | Write to the error log. | mixed |
writeAlerts() | Write user-friendly error messages to the alert message stream. | mixed |
determineRenderer() | Determine which renderer to use based on content type Overloaded $renderer from calling class takes precedence over all. | ErrorRendererInterface |
determineStatusCode() | Resolve the status code to return in the response from this handler. | int |
determineUserMessages() | Resolve a list of error messages to present to the end user. | array |
logError() | Monolog logging for errors. | mixed |
determineContentType() | Determine which content type we know about is wanted using Accept header. | string |
Properties
$ci
protected
ContainerInterface
$ci
$request
protected
ServerRequestInterface
$request
$response
protected
ResponseInterface
$response
$exception
protected
Throwable
$exception
$renderer
protected
ErrorRendererInterface
$renderer
= null
$contentType
protected
string
$contentType
$statusCode
protected
int
$statusCode
$displayErrorDetails
Tells the handler whether or not to output detailed error information to the client.
protected
bool
$displayErrorDetails
$knownContentTypes
Known handled content types.
protected
array
$knownContentTypes
= ['application/json', 'application/xml', 'text/xml', 'text/html', 'text/plain']
Methods
__construct()
Create a new ExceptionHandler object.
public
__construct(
$ci :
ContainerInterface
, $request :
ServerRequestInterface
, $response :
ResponseInterface
, $exception :
Throwable
[, $displayErrorDetails :
bool
= false ]
)
: mixed
Parameters
- $ci : ContainerInterface
- $request : ServerRequestInterface
The most recent Request object
- $response : ResponseInterface
The most recent Response object
- $exception : Throwable
The caught Exception object
- $displayErrorDetails : bool = false
Return values
mixedhandle()
Handle the caught exception.
public
handle(
)
: ResponseInterface
The handler may render a detailed debugging error page, a generic error page, write to logs, and/or add messages to the alert stream.
Return values
ResponseInterfacerenderDebugResponse()
Render a detailed response with debugging information.
public
renderDebugResponse(
)
: ResponseInterface
Return values
ResponseInterfacerenderGenericResponse()
Render a generic, user-friendly response without sensitive debugging information.
public
renderGenericResponse(
)
: ResponseInterface
Return values
ResponseInterfacewriteToErrorLog()
Write to the error log.
public
writeToErrorLog(
)
: mixed
Return values
mixedwriteAlerts()
Write user-friendly error messages to the alert message stream.
public
writeAlerts(
)
: mixed
Return values
mixeddetermineRenderer()
Determine which renderer to use based on content type Overloaded $renderer from calling class takes precedence over all.
protected
determineRenderer(
)
: ErrorRendererInterface
Tags
Return values
ErrorRendererInterfacedetermineStatusCode()
Resolve the status code to return in the response from this handler.
protected
determineStatusCode(
)
: int
Return values
intdetermineUserMessages()
Resolve a list of error messages to present to the end user.
protected
determineUserMessages(
)
: array
Return values
arraylogError()
Monolog logging for errors.
protected
logError(
$message :
string
)
: mixed
Parameters
- $message : string
Return values
mixeddetermineContentType()
Determine which content type we know about is wanted using Accept header.
protected
determineContentType(
$request :
ServerRequestInterface
[, $ajaxDebug :
bool
= false ]
)
: string
Note: This method is a bare-bones implementation designed specifically for Slim's error handling requirements. Consider a fully-feature solution such as willdurand/negotiation for any other situation.
Parameters
- $request : ServerRequestInterface
- $ajaxDebug : bool = false