Move into modularizing the container definitions for the application bootstrap.

This commit is contained in:
Dave Smith-Hayes 2025-06-19 08:46:19 -04:00
parent 5389b59c20
commit f8911d9d14
2 changed files with 46 additions and 26 deletions

View File

@ -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

View File

@ -0,0 +1,42 @@
<?php
namespace Slovocast\Infrastructure\Application;
use Slovocast\Infrastructure\Application\DefinitionInterface;
use Slovocast\Infrastructure\Api\User\UserSessionManagerInterface;
use Slovocast\Infrastructure\User\UserSessionManager;
use Slovocast\Middleware\SessionMiddleware;
use Odan\Session\PhpSession;
use Odan\Session\SessionInterface;
use Odan\Session\SessionManagerInterface;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
class SessionDefintion implements DefinitionInterface
{
public function define(): array
{
return [
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));
},
];
}
}