From d45800cfc47901095a276e0357bef8697c95d86e Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Tue, 3 Dec 2024 16:00:27 +0000 Subject: [PATCH] Avoid creating a new Twig instance, get it from the request set up in the middleware --- app/src/Controller/Controller.php | 2 +- .../Infrastructure/Api/Database/DatabaseHandlerInterface.php | 3 +++ app/src/Infrastructure/Database/DatabaseHandler.php | 2 +- app/src/Middlewares.php | 1 - 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/Controller/Controller.php b/app/src/Controller/Controller.php index 63b102f..9db6937 100644 --- a/app/src/Controller/Controller.php +++ b/app/src/Controller/Controller.php @@ -32,7 +32,7 @@ abstract class Controller $this->response = $response; $this->args = $args; $this->routeContext = RouteContext::fromRequest($this->request); - $this->view = Twig::fromRequest($request); + $this->view = $this->request->getAttribute('view'); return $this->handle(); } diff --git a/app/src/Infrastructure/Api/Database/DatabaseHandlerInterface.php b/app/src/Infrastructure/Api/Database/DatabaseHandlerInterface.php index f0a9c82..99afc82 100644 --- a/app/src/Infrastructure/Api/Database/DatabaseHandlerInterface.php +++ b/app/src/Infrastructure/Api/Database/DatabaseHandlerInterface.php @@ -2,11 +2,14 @@ namespace Slovocast\Infrastructure\Api\Database; +use ReturnTypeWillChange; + interface DatabaseHandlerInterface { /** * @return mixed The return must be an active connection to a database. */ + #[ReturnTypeWillChange] public function getConnection(); /** diff --git a/app/src/Infrastructure/Database/DatabaseHandler.php b/app/src/Infrastructure/Database/DatabaseHandler.php index 84519e8..c96feda 100644 --- a/app/src/Infrastructure/Database/DatabaseHandler.php +++ b/app/src/Infrastructure/Database/DatabaseHandler.php @@ -33,7 +33,7 @@ class DatabaseHandler implements DatabaseHandlerInterface /** * @return PDO For this particular Handler we will return the PDO object */ - public function getConnection() + public function getConnection(): PDO { return $this->handle; } diff --git a/app/src/Middlewares.php b/app/src/Middlewares.php index b52d30e..067079f 100644 --- a/app/src/Middlewares.php +++ b/app/src/Middlewares.php @@ -3,7 +3,6 @@ namespace Slovocast; use League\Config\Configuration; -use Odan\Session\Middleware\SessionStartMiddleware; use Odan\Session\SessionInterface; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface;