From e58c442ccf7ed871bab7bc803e5fb8247bde50ed Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Thu, 25 Jul 2024 20:32:26 -0400 Subject: [PATCH] Add pool interfaces, refactor imports in the bootstrap, re-organize some of the APIs --- app/src/Bootstrap.php | 48 ++++++++----------- app/src/Controller/User/LoginUserAction.php | 8 ++-- .../Domain/Repository/User/UserRepository.php | 6 +-- .../Api/Database/ConnectionInterface.php | 2 +- .../Api/Database/ConnectionPoolInterface.php | 3 +- .../User/UserAuthorizationInterface.php | 4 +- .../User/BasicUserAuthorization.php | 4 +- 7 files changed, 34 insertions(+), 41 deletions(-) rename app/src/Infrastructure/{ => Api}/User/UserAuthorizationInterface.php (72%) diff --git a/app/src/Bootstrap.php b/app/src/Bootstrap.php index f4341ae..f9f1625 100644 --- a/app/src/Bootstrap.php +++ b/app/src/Bootstrap.php @@ -2,41 +2,33 @@ namespace Slovocast; -use Exception; -use Psr\Container\ContainerExceptionInterface; -use Psr\Container\NotFoundExceptionInterface; -use Slim\App; -use Slim\Factory\AppFactory; - -use League\Config\Configuration; - -use Psr\Container\ContainerInterface; -use Psr\Http\Message\ResponseFactoryInterface; use DI\Container; use DI\ContainerBuilder; - -use Slim\Psr7\Factory\ResponseFactory; - -use Slovocast\Configuration\SiteInformationSchema; -use Slovocast\Configuration\DatabaseConnectionSchema; -use Slovocast\Configuration\SessionSchema; - -use Twig\Error\LoaderError; -use Slovocast\Domain\Repository\User\UserRepositoryInterface; -use Slovocast\Domain\Repository\User\UserRepository; - -use Slovocast\Infrastructure\User\UserAuthorizationInterface; -use Slovocast\Infrastructure\User\BasicUserAuthorization; - -use React\Mysql\MysqlClient; - -use Psr\Log\LoggerInterface; -use Monolog\Logger; +use Exception; +use League\Config\Configuration; use Monolog\Handler\StreamHandler; use Monolog\Level; +use Monolog\Logger; use Odan\Session\PhpSession; use Odan\Session\SessionInterface; use Odan\Session\SessionManagerInterface; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\ContainerInterface; +use Psr\Container\NotFoundExceptionInterface; +use Psr\Http\Message\ResponseFactoryInterface; +use Psr\Log\LoggerInterface; +use React\Mysql\MysqlClient; +use Slim\App; +use Slim\Factory\AppFactory; +use Slim\Psr7\Factory\ResponseFactory; +use Slovocast\Configuration\DatabaseConnectionSchema; +use Slovocast\Configuration\SessionSchema; +use Slovocast\Configuration\SiteInformationSchema; +use Slovocast\Domain\Repository\User\UserRepository; +use Slovocast\Domain\Repository\User\UserRepositoryInterface; +use Slovocast\Infrastructure\Api\User\UserAuthorizationInterface; +use Slovocast\Infrastructure\User\BasicUserAuthorization; +use Twig\Error\LoaderError; /** * Defines here are used globally diff --git a/app/src/Controller/User/LoginUserAction.php b/app/src/Controller/User/LoginUserAction.php index eff121a..133a640 100644 --- a/app/src/Controller/User/LoginUserAction.php +++ b/app/src/Controller/User/LoginUserAction.php @@ -2,12 +2,12 @@ namespace Slovocast\Controller\User; +use Odan\Session\SessionInterface; +use Psr\Http\Message\ResponseInterface as Response; use Slovocast\Controller\Controller; use Slovocast\Domain\Repository\User\UserRepositoryInterface; -use Slovocast\Infrastructure\User\UserAuthorizationInterface; use Slovocast\Exception\EntityNotFoundException; -use Psr\Http\Message\ResponseInterface as Response; -use Odan\Session\SessionInterface; +use Slovocast\Infrastructure\Api\User\UserAuthorizationInterface; class LoginUserAction extends Controller { @@ -34,7 +34,7 @@ class LoginUserAction extends Controller } // start the session - $this->session->set('user', [ + $this->session->set('user', [ 'id' => $user->getId(), 'authenticated' => true ]); diff --git a/app/src/Domain/Repository/User/UserRepository.php b/app/src/Domain/Repository/User/UserRepository.php index 37bab0b..e394740 100644 --- a/app/src/Domain/Repository/User/UserRepository.php +++ b/app/src/Domain/Repository/User/UserRepository.php @@ -2,11 +2,11 @@ namespace Slovocast\Domain\Repository\User; -use function React\Async\await; use React\Mysql\MysqlClient; -use Slovocast\Infrastructure\User\UserAuthorizationInterface; -use Slovocast\Exception\EntityNotFoundException; use Slovocast\Domain\Entity\User; +use Slovocast\Exception\EntityNotFoundException; +use Slovocast\Infrastructure\Api\User\UserAuthorizationInterface; +use function React\Async\await; class UserRepository implements UserRepositoryInterface { diff --git a/app/src/Infrastructure/Api/Database/ConnectionInterface.php b/app/src/Infrastructure/Api/Database/ConnectionInterface.php index 0cc7599..509b763 100644 --- a/app/src/Infrastructure/Api/Database/ConnectionInterface.php +++ b/app/src/Infrastructure/Api/Database/ConnectionInterface.php @@ -2,7 +2,7 @@ namespace Slovocast\Infrastructure\Api\Database; -interface ConnectionInterface +interface PooledConnectionInterface { public function release(): void; } diff --git a/app/src/Infrastructure/Api/Database/ConnectionPoolInterface.php b/app/src/Infrastructure/Api/Database/ConnectionPoolInterface.php index fb9162e..18754e7 100644 --- a/app/src/Infrastructure/Api/Database/ConnectionPoolInterface.php +++ b/app/src/Infrastructure/Api/Database/ConnectionPoolInterface.php @@ -4,7 +4,8 @@ namespace Slovocast\Infrastructure\Api\Database; interface ConnectionPoolInterface { - public function getTotalConnectionCount(): int; + public function getFreeConnectionsCount(): int; + public function getActiveConnectionsCount(): int; public function hasFreeConnection(): bool; public function getConnection(): ConnectionInterface; public function releaseConnection(ConnectionInterface $connection): void; diff --git a/app/src/Infrastructure/User/UserAuthorizationInterface.php b/app/src/Infrastructure/Api/User/UserAuthorizationInterface.php similarity index 72% rename from app/src/Infrastructure/User/UserAuthorizationInterface.php rename to app/src/Infrastructure/Api/User/UserAuthorizationInterface.php index ab7d445..e8da532 100644 --- a/app/src/Infrastructure/User/UserAuthorizationInterface.php +++ b/app/src/Infrastructure/Api/User/UserAuthorizationInterface.php @@ -1,11 +1,11 @@