phpmyadmin/libraries/classes/Middleware/ErrorHandling.php
Maurício Meneghini Fauth 5dc23aec19
Create the ErrorHandling middleware
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2023-08-08 16:14:34 -03:00

37 lines
977 B
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Middleware;
use PhpMyAdmin\ErrorHandler;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use function restore_error_handler;
use function restore_exception_handler;
use function set_error_handler;
use function set_exception_handler;
final class ErrorHandling implements MiddlewareInterface
{
public function __construct(private readonly ErrorHandler $errorHandler)
{
}
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
set_exception_handler($this->errorHandler->handleException(...));
set_error_handler($this->errorHandler->handleError(...));
$response = $handler->handle($request);
restore_error_handler();
restore_exception_handler();
return $response;
}
}