class ProductionHandler extends Handler implements HandlerInterface

Production handler.

Traits

Basic content negotiation.

Properties

protected Request $request Request instance.
protected Response $response Response instance.
protected ViewFactory|null $view View factory instance.

Methods

bool
expectsType(array $mimeTypes, string|null $suffix = null)

Does the client expect the provided mime type?

bool
expectsJson()

Does the client expect JSON?

bool
expectsXml()

Does the client expect XML?

bool
respondWithType(array $mimeTypes, string|null $suffix = null)

Should we respond with the provided mime type?

bool
respondWithJson()

Should we respond with JSON?

bool
respondWithXml()

Should we respond with XML?

int
getStatusCode(Throwable $exception)

Returns the status code that we should send.

from Handler
sendResponse(Response $response, Throwable $exception)

Sends response and adds any aditional headers.

from Handler
__construct(Request $request, Response $response, ViewFactory|null $view = null)

Constructor.

array
getStatusCodeAndMessage(Throwable $exception)

Returns status code and message.

string
getExceptionAsJson(Throwable $exception)

Return a JSON representation of the exception.

string
getExceptionAsXml(Throwable $exception)

Return a XML representation of the exception.

string
getExceptionAsRenderedView(Throwable $exception)

Returns a rendered error view.

string
getExceptionAsPlainText(Throwable $exception)

Returns a plain text representation of the error.

string
getBody(Throwable $exception)

Returns a response body.

mixed
handle(Throwable $exception)

Handles the exception.

Details

protected bool expectsType(array $mimeTypes, string|null $suffix = null)

Does the client expect the provided mime type?

Parameters

array $mimeTypes Mime types
string|null $suffix Mime type suffix

Return Value

bool

protected bool expectsJson()

Does the client expect JSON?

Return Value

bool

protected bool expectsXml()

Does the client expect XML?

Return Value

bool

protected bool respondWithType(array $mimeTypes, string|null $suffix = null)

Should we respond with the provided mime type?

Parameters

array $mimeTypes Mime types
string|null $suffix Mime type suffix

Return Value

bool

protected bool respondWithJson()

Should we respond with JSON?

Return Value

bool

protected bool respondWithXml()

Should we respond with XML?

Return Value

bool

in Handler at line 31
protected int getStatusCode(Throwable $exception)

Returns the status code that we should send.

Parameters

Throwable $exception Exception

Return Value

int

in Handler at line 42
protected sendResponse(Response $response, Throwable $exception)

Sends response and adds any aditional headers.

Parameters

Response $response Response
Throwable $exception Exception

at line 54
__construct(Request $request, Response $response, ViewFactory|null $view = null)

Constructor.

Parameters

Request $request Request
Response $response Response
ViewFactory|null $view View factory

at line 74
protected array getStatusCodeAndMessage(Throwable $exception)

Returns status code and message.

Parameters

Throwable $exception Exception

Return Value

array

at line 95
protected string getExceptionAsJson(Throwable $exception)

Return a JSON representation of the exception.

Parameters

Throwable $exception Exception

Return Value

string

at line 106
protected string getExceptionAsXml(Throwable $exception)

Return a XML representation of the exception.

Parameters

Throwable $exception Exception

Return Value

string

at line 125
protected string getExceptionAsRenderedView(Throwable $exception)

Returns a rendered error view.

Parameters

Throwable $exception Exception

Return Value

string

at line 155
protected string getExceptionAsPlainText(Throwable $exception)

Returns a plain text representation of the error.

Parameters

Throwable $exception Exception

Return Value

string

at line 168
protected string getBody(Throwable $exception)

Returns a response body.

Parameters

Throwable $exception Exception

Return Value

string

at line 199
mixed handle(Throwable $exception)

Handles the exception.

Parameters

Throwable $exception Exception to handle

Return Value

mixed