Compare commits

...

3 Commits

Author SHA1 Message Date
a16f916b05
#14 Session setup
Some checks failed
Build and test. / build (push) Successful in 15s
Build and test. / test (push) Failing after 13s
Build and test. / cleanup (push) Successful in 5s
2025-10-01 13:05:41 +03:00
32af4da93c
#14 Session config 2025-10-01 12:57:05 +03:00
695cfa2fc3
#14 Dependency install 2025-10-01 12:45:58 +03:00
5 changed files with 49 additions and 1 deletions

View File

@ -17,7 +17,8 @@
"php-di/slim-bridge": "^3.4",
"monolog/monolog": "^3.9",
"slim/twig-view": "^3.4",
"cuyz/valinor": "^2.1"
"cuyz/valinor": "^2.1",
"odan/session": "^6.4"
},
"require-dev": {
"phpstan/phpstan": "^2.1",

View File

@ -7,5 +7,11 @@
"displayErrorDetails": true,
"logErrors": true,
"logErrorDetails": true
},
"session": {
"name": "runx-session",
"lifetime": 86400,
"secure": true,
"httpOnly": true
}
}

View File

@ -6,6 +6,9 @@ use CuyZ\Valinor\MapperBuilder;
use DI\ContainerBuilder;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;
use Odan\Session\PhpSession;
use Odan\Session\SessionInterface;
use Odan\Session\SessionManagerInterface;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Log\LoggerInterface;
@ -81,5 +84,17 @@ return function (ContainerBuilder $builder): void {
return new RenderService($twig, $responseFactory, $logger);
},
// Session
SessionInterface::class => function (ContainerInterface $container) {
/** @var Config $config */
$config = $container->get(Config::class);
return new PhpSession($config->session->toArray());
},
SessionManagerInterface::class => function (ContainerInterface $container) {
return $container->get(SessionInterface::class);
},
]);
};

View File

@ -9,5 +9,6 @@ final class Config
public function __construct(
public readonly LoggerConfig $logger,
public readonly ErrorHandlingConfig $errorHandling,
public readonly SessionConfig $session,
) {}
}

View File

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace Runx\Infrastructure\Config;
final class SessionConfig
{
public function __construct(
public readonly string $name,
public readonly int $lifetime,
public readonly bool $secure,
public readonly bool $httpOnly,
) {}
public function toArray(): array
{
return [
'name' => $this->name,
'lifetime' => $this->lifetime,
'secure' => $this->secure,
'httponly' => $this->httpOnly,
];
}
}