# PHP package for error handling
The HttpSoft\ErrorHandler package implements Psr\Http\Server\MiddlewareInterface and Psr\Http\Server\RequestHandlerInterface.
This package requires PHP version 7.4 or later.
Package installation:
composer require httpsoft/http-error-handler
# API
- HttpSoft\ErrorHandler\ErrorHandler — class, that implements Psr\Http\Server\RequestHandlerInterface.
- HttpSoft\ErrorHandler\ErrorHandlerMiddleware — class, that implements Psr\Http\Server\MiddlewareInterface.
- HttpSoft\ErrorHandler\ErrorHandlerTrait — trait containing methods for handling errors, used within HttpSoft\ErrorHandler\ErrorHandler and HttpSoft\ErrorHandler\ErrorHandlerMiddleware.
- HttpSoft\ErrorHandler\ErrorResponseGenerator — response generator with information about the handled error by default; implements HttpSoft\ErrorHandler\ErrorResponseGeneratorInterface.
Interfaces:
- HttpSoft\ErrorHandler\ErrorListenerInterface.
- HttpSoft\ErrorHandler\ErrorResponseGeneratorInterface.
# Usage
use HttpSoft\ErrorHandler\ErrorHandler;
use HttpSoft\ErrorHandler\ErrorHandlerMiddleware;
/**
* @var Psr\Http\Message\ServerRequestInterface $request
* @var Psr\Http\Server\RequestHandlerInterface $handler
* @var HttpSoft\ErrorHandler\ErrorListenerInterface $listener
* @var HttpSoft\ErrorHandler\ErrorResponseGeneratorInterface $responseGenerator
*/
// Usage ErrorHandler
$errorHandler = new ErrorHandler($handler, $responseGenerator);
$errorHandler->addListener($listener);
$response = $errorHandler->handle($request);
// Usage ErrorHandlerMiddleware
$errorHandler = new ErrorHandlerMiddleware($responseGenerator);
$errorHandler->addListener($listener);
$response = $errorHandler->process($request, $handler);
Detailed description of using HttpSoft\ErrorHandler\ErrorHandler
see here.
Detailed description of using HttpSoft\ErrorHandler\ErrorHandlerMiddleware
see here.
Detailed description of using HttpSoft\ErrorHandler\ErrorHandlerTrait
see here.