Optimized controller / services structure

This commit is contained in:
Bernd Bestel
2026-04-20 22:46:47 +02:00
parent 496f8ece8d
commit 6210077984
66 changed files with 1087 additions and 1179 deletions

View File

@@ -2,7 +2,10 @@
namespace Grocy\Controllers;
use Grocy\Controllers\Api\BaseApiController;
use Grocy\Services\ApplicationService;
use DI\Container;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;
use Slim\Exception\HttpException;
@@ -12,17 +15,17 @@ use Throwable;
class ExceptionController extends BaseApiController
{
public function __construct(\Slim\App $app, Container $container)
public function __construct(Container $container, ResponseFactoryInterface $responseFactory)
{
parent::__construct($container);
$this->app = $app;
$this->ResponseFactory = $responseFactory;
}
private $app;
private $ResponseFactory;
public function __invoke(ServerRequestInterface $request, Throwable $exception, bool $displayErrorDetails, bool $logErrors, bool $logErrorDetails, ?LoggerInterface $logger = null)
{
$response = $this->app->getResponseFactory()->createResponse();
$response = $this->ResponseFactory->createResponse();
$isApiRoute = string_starts_with($request->getUri()->getPath(), '/api/');
if (!defined('GROCY_AUTHENTICATED'))
@@ -33,7 +36,6 @@ class ExceptionController extends BaseApiController
if ($isApiRoute)
{
$status = 500;
if ($exception instanceof HttpException)
{
$status = $exception->getCode();
@@ -62,21 +64,21 @@ class ExceptionController extends BaseApiController
define('GROCY_AUTHENTICATED', false);
}
return $this->renderPage($response->withStatus(404), 'errors/404', [
return $this->RenderPage($response->withStatus(404), 'errors/404', [
'exception' => $exception
]);
}
if ($exception instanceof HttpForbiddenException)
{
return $this->renderPage($response->withStatus(403), 'errors/403', [
return $this->RenderPage($response->withStatus(403), 'errors/403', [
'exception' => $exception
]);
}
return $this->renderPage($response->withStatus(500), 'errors/500', [
return $this->RenderPage($response->withStatus(500), 'errors/500', [
'exception' => $exception,
'systemInfo' => $this->getApplicationService()->GetSystemInfo()
'systemInfo' => ApplicationService::GetInstance()->GetSystemInfo()
]);
}
}