phpmyadmin/libraries/classes/Middleware/PhpExtensionsChecking.php
Maurício Meneghini Fauth daad3ab13a
Add support for PSR-15 middleware
Creates the Http/Handler/QueueRequestHandler class to handle the
middleware queue.
Extracts the PHP extensions checking into a middleware.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2023-08-08 16:14:34 -03:00

47 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Middleware;
use Fig\Http\Message\StatusCodeInterface;
use PhpMyAdmin\Application;
use PhpMyAdmin\Exceptions\MissingExtensionException;
use PhpMyAdmin\Http\Factory\ResponseFactory;
use PhpMyAdmin\Template;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
final class PhpExtensionsChecking implements MiddlewareInterface
{
public function __construct(
private readonly Application $application,
private readonly Template $template,
private readonly ResponseFactory $responseFactory,
) {
}
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
try {
$this->application->checkRequiredPhpExtensions();
} catch (MissingExtensionException $exception) {
// Disables template caching because the cache directory is not known yet.
$this->template->disableCache();
$output = $this->template->render('error/generic', [
'lang' => 'en',
'dir' => 'ltr',
'error_message' => $exception->getMessage(),
]);
$response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR);
$response->getBody()->write($output);
return $response;
}
return $handler->handle($request);
}
}