don't over engineer the bootstrapping.
This commit is contained in:
parent
f8911d9d14
commit
7c4012c9fd
@ -33,6 +33,7 @@ use Slim\App;
|
|||||||
use Slim\Factory\AppFactory;
|
use Slim\Factory\AppFactory;
|
||||||
use Slim\Psr7\Factory\ResponseFactory;
|
use Slim\Psr7\Factory\ResponseFactory;
|
||||||
use Slovocast\Infrastructure\Application\LoggerDefinition;
|
use Slovocast\Infrastructure\Application\LoggerDefinition;
|
||||||
|
use Slovocast\Infrastructure\Application\ResponseFactoryDefinition;
|
||||||
use Slovocast\Infrastructure\Application\SessionDefintion;
|
use Slovocast\Infrastructure\Application\SessionDefintion;
|
||||||
use Slovocast\Middleware\SessionMiddleware;
|
use Slovocast\Middleware\SessionMiddleware;
|
||||||
use Twig\Error\LoaderError;
|
use Twig\Error\LoaderError;
|
||||||
@ -120,20 +121,51 @@ class Bootstrap
|
|||||||
protected static function initContainer(): Container
|
protected static function initContainer(): Container
|
||||||
{
|
{
|
||||||
$containerBuilder = new ContainerBuilder();
|
$containerBuilder = new ContainerBuilder();
|
||||||
|
|
||||||
$config = self::initConfig();
|
$config = self::initConfig();
|
||||||
|
|
||||||
|
$containerDefinitions = array_merge(
|
||||||
|
[ 'config' => $config ],
|
||||||
|
(new LoggerDefinition())->define(),
|
||||||
|
(new SessionDefintion())->define(),
|
||||||
|
(new ResponseFactoryDefinition())->define(),
|
||||||
|
);
|
||||||
|
|
||||||
$containerBuilder->addDefinitions([
|
$containerBuilder->addDefinitions([
|
||||||
'config' => $config,
|
'config' => $config,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Global logging
|
* Global logging
|
||||||
*/
|
*/
|
||||||
(new LoggerDefinition())->define(),
|
LoggerInterface::class => function (ContainerInterface $c) {
|
||||||
|
$logger = new Logger("default");
|
||||||
|
$logger->pushHandler(new StreamHandler('php://stdout', Level::Info));
|
||||||
|
return $logger;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Session and Flash classes here
|
* Session and Flash classes here
|
||||||
*/
|
*/
|
||||||
(new SessionDefintion())->define(),
|
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));
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Application DI
|
* Application DI
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Slovocast\Infrastructure\Application;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ideally this would define the Container definition required for setting up
|
|
||||||
* dependencies within the PHP DI ContainerBuilder class
|
|
||||||
*/
|
|
||||||
interface DefinitionInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @return array<string, mixed> The definition structure used for setting
|
|
||||||
* up a Container
|
|
||||||
*/
|
|
||||||
public function define(): array;
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Slovocast\Infrastructure\Application;
|
|
||||||
|
|
||||||
use Psr\Container\ContainerInterface;
|
|
||||||
use Psr\Log\LoggerInterface;
|
|
||||||
use Monolog\Handler\StreamHandler;
|
|
||||||
use Monolog\Level;
|
|
||||||
use Monolog\Logger;
|
|
||||||
use Slovocast\Infrastructure\Application\DefinitionInterface;
|
|
||||||
|
|
||||||
class LoggerDefinition implements DefinitionInterface
|
|
||||||
{
|
|
||||||
public function define(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
LoggerInterface::class => function (ContainerInterface $c) {
|
|
||||||
$logger = new Logger("default");
|
|
||||||
$logger->pushHandler(new StreamHandler('php://stdout', Level::Info));
|
|
||||||
return $logger;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
<?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));
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user