PHP Class Psr7Middlewares\Middleware\ErrorHandler

Inheritance: use trait Psr7Middlewares\Utils\CallableTrait
Show file Open project: oscarotero/psr7-middlewares Class Usage Examples

Public Methods

Method Description
__construct ( callable | string | null $handler = null ) Constructor.
__invoke ( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $next ) : Psr\Http\Message\ResponseInterface Execute the middleware.
catchExceptions ( boolean $catch = true ) : self Configure the catchExceptions.
getException ( Psr\Http\Message\ServerRequestInterface $request ) : Exception | null Returns the exception throwed.
statusCode ( callable $statusCodeValidator ) : self Configure the status code validator.

Private Methods

Method Description
defaultHandler ( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response ) : string Default handler.
errorHtml ( integer $statusCode, string $message ) : string Print the error as html.
errorImage ( integer $statusCode, string $message, string $output ) : string Print the error as image.
errorJson ( integer $statusCode, string $message ) : string Print the error as json.
errorSvg ( integer $statusCode, string $message ) : string Print the error as svg image.
errorText ( integer $statusCode, string $message ) : string Print the error as plain text.
errorXml ( integer $statusCode, string $message ) : string Print the error as xml.
isError ( integer $statusCode ) : boolean Check whether the status code represents an error or not.

Method Details

__construct() public method

Constructor.
public __construct ( callable | string | null $handler = null )
$handler callable | string | null

__invoke() public method

Execute the middleware.
public __invoke ( Psr\Http\Message\ServerRequestInterface $request, Psr\Http\Message\ResponseInterface $response, callable $next ) : Psr\Http\Message\ResponseInterface
$request Psr\Http\Message\ServerRequestInterface
$response Psr\Http\Message\ResponseInterface
$next callable
return Psr\Http\Message\ResponseInterface

catchExceptions() public method

Configure the catchExceptions.
public catchExceptions ( boolean $catch = true ) : self
$catch boolean
return self

getException() public static method

Returns the exception throwed.
public static getException ( Psr\Http\Message\ServerRequestInterface $request ) : Exception | null
$request Psr\Http\Message\ServerRequestInterface
return Exception | null

statusCode() public method

Configure the status code validator.
public statusCode ( callable $statusCodeValidator ) : self
$statusCodeValidator callable
return self