From 97d9784858284d485766e53a7b3b0eea7e61a6c6 Mon Sep 17 00:00:00 2001 From: Oleg Kasyanov Date: Sun, 21 Jan 2024 17:00:40 +0400 Subject: [PATCH] Configuration options are supplemented --- src/SessionMiddlewareFactory.php | 13 ++++++++++--- tests/unit/SessionMiddlewareFactoryTest.php | 4 ++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/SessionMiddlewareFactory.php b/src/SessionMiddlewareFactory.php index dfa7e80..34548c0 100644 --- a/src/SessionMiddlewareFactory.php +++ b/src/SessionMiddlewareFactory.php @@ -17,9 +17,16 @@ class SessionMiddlewareFactory */ public function __invoke(ContainerInterface $container): SessionMiddleware { - /** @var ConfigInterface $configContainer */ - $configContainer = $container->get(ConfigInterface::class); - $config = (array) $configContainer->get('session', []); + if ($container->has(ConfigInterface::class)) { + /** @var ConfigInterface $configContainer */ + $configContainer = $container->get(ConfigInterface::class); + $config = (array) $configContainer->get('session', []); + } elseif ($container->has('config')) { + $configArray = (array) $container->get('config'); + $config = $configArray['session'] ?? []; + } else { + $config = []; + } $session = new SessionHandler( $container->get(PDO::class), diff --git a/tests/unit/SessionMiddlewareFactoryTest.php b/tests/unit/SessionMiddlewareFactoryTest.php index 0783a8e..1fec117 100644 --- a/tests/unit/SessionMiddlewareFactoryTest.php +++ b/tests/unit/SessionMiddlewareFactoryTest.php @@ -107,6 +107,10 @@ private function getContainer(array $options): ContainerInterface ->willReturn($options); $container = $this->createMock(ContainerInterface::class); + $container + ->method('has') + ->with(ConfigInterface::class) + ->willReturn(true); $container ->method('get') ->willReturnCallback(