From f8911d9d14e87c0536d7155cd902da5ec3254261 Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Thu, 19 Jun 2025 08:46:19 -0400 Subject: [PATCH] Move into modularizing the container definitions for the application bootstrap. --- app/src/Bootstrap.php | 30 ++----------- .../Application/SessionDefinition.php | 42 +++++++++++++++++++ 2 files changed, 46 insertions(+), 26 deletions(-) create mode 100644 app/src/Infrastructure/Application/SessionDefinition.php diff --git a/app/src/Bootstrap.php b/app/src/Bootstrap.php index 5ef7885..ec26019 100644 --- a/app/src/Bootstrap.php +++ b/app/src/Bootstrap.php @@ -32,6 +32,8 @@ use Psr\Log\LoggerInterface; use Slim\App; use Slim\Factory\AppFactory; use Slim\Psr7\Factory\ResponseFactory; +use Slovocast\Infrastructure\Application\LoggerDefinition; +use Slovocast\Infrastructure\Application\SessionDefintion; use Slovocast\Middleware\SessionMiddleware; use Twig\Error\LoaderError; @@ -126,36 +128,12 @@ class Bootstrap /** * Global logging */ - LoggerInterface::class => function() { - $logger = new Logger("default"); - $logger->pushHandler(new StreamHandler('php://stdout', Level::Info)); - return $logger; - }, + (new LoggerDefinition())->define(), /** * Session and Flash classes here */ - SessionManagerInterface::class => function (ContainerInterface $container) { - return $container->get(SessionInterface::class); - }, - SessionInterface::class => function (ContainerInterface $container) { - $options = $container->get('config')->get('session'); - return new PhpSession($options); - }, - 'session' => function (ContainerInterface $container) { - return $container->get(SessionInterface::class); - }, - SessionMiddleware::class => function (ContainerInterface $container) { - return new SessionMiddleware( - $container->get(SessionManagerInterface::class), - $container->get(SessionInterface::class), - $container->get(LoggerInterface::class) - ); - }, - - UserSessionManagerInterface::class => function (ContainerInterface $container) { - return new UserSessionManager($container->get(SessionInterface::class)); - }, + (new SessionDefintion())->define(), /** * Application DI diff --git a/app/src/Infrastructure/Application/SessionDefinition.php b/app/src/Infrastructure/Application/SessionDefinition.php new file mode 100644 index 0000000..cdd6c73 --- /dev/null +++ b/app/src/Infrastructure/Application/SessionDefinition.php @@ -0,0 +1,42 @@ + function (ContainerInterface $container) { + return $container->get(SessionInterface::class); + }, + SessionInterface::class => function (ContainerInterface $container) { + $options = $container->get('config')->get('session'); + return new PhpSession($options); + }, + 'session' => function (ContainerInterface $container) { + return $container->get(SessionInterface::class); + }, + SessionMiddleware::class => function (ContainerInterface $container) { + return new SessionMiddleware( + $container->get(SessionManagerInterface::class), + $container->get(SessionInterface::class), + $container->get(LoggerInterface::class) + ); + }, + UserSessionManagerInterface::class => function (ContainerInterface $container) { + return new UserSessionManager($container->get(SessionInterface::class)); + }, + ]; + } +}