Files
oficial/app/src/Middleware/NotAllowed.php
aldarien 307f2ac7d7 feature/cierres (#25)
Varios cambios

Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl>
Reviewed-on: #25
2025-07-22 13:18:00 +00:00

31 lines
1.1 KiB
PHP

<?php
namespace Incoviba\Middleware;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Psr\Log\LoggerInterface;
use Slim\Exception\HttpMethodNotAllowedException;
use Incoviba\Common\Alias\View;
class NotAllowed
{
public function __construct(protected LoggerInterface $logger, protected ResponseFactoryInterface $responseFactory,
protected View $view) {}
public function __invoke(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
try {
return $handler->handle($request);
} catch (HttpMethodNotAllowedException $exception) {
$this->logger->warning($exception);
$response = $this->responseFactory->createResponse(405, 'Method Not Allowed');
if (str_contains($request->getUri()->getPath(), '/api')) {
return $response;
}
return $this->view->render($response, 'not_allowed');
}
}
}