From 5da41e63c95a86e42ec647037398a85dbc685297 Mon Sep 17 00:00:00 2001 From: Milos Stojanovic Date: Wed, 19 Jun 2019 09:23:20 +0200 Subject: [PATCH] session handler config upd --- .../Session/Adapters/SessionStorage.php | 2 +- configuration_sample.php | 15 ++++------ docs/configuration/logging.md | 2 +- docs/configuration/session.md | 28 ++++++++----------- tests/backend/Unit/Auth/AuthTest.php | 9 ++---- tests/backend/Unit/SessionStorageTest.php | 9 ++---- tests/backend/configuration.php | 9 ++---- 7 files changed, 28 insertions(+), 46 deletions(-) diff --git a/backend/Services/Session/Adapters/SessionStorage.php b/backend/Services/Session/Adapters/SessionStorage.php index da99aaa..64db7e2 100644 --- a/backend/Services/Session/Adapters/SessionStorage.php +++ b/backend/Services/Session/Adapters/SessionStorage.php @@ -30,7 +30,7 @@ class SessionStorage implements Service, SessionStorageInterface { // we don't have a previous session attached if (! $this->getSession()) { - $handler = $config['available'][$config['session_handler']]; + $handler = $config['handler']; $session = new Session($handler()); $session->setName('filegator'); diff --git a/configuration_sample.php b/configuration_sample.php index 2ce33c8..96104e3 100644 --- a/configuration_sample.php +++ b/configuration_sample.php @@ -32,16 +32,13 @@ return [ 'Filegator\Services\Session\SessionStorageInterface' => [ 'handler' => '\Filegator\Services\Session\Adapters\SessionStorage', 'config' => [ - 'session_handler' => 'filesession', - 'available' => [ - 'filesession' => function () { - $save_path = null; // use default system path - //$save_path = __DIR__.'/private/sessions'; - $handler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler($save_path); + 'handler' => function () { + $save_path = null; // use default system path + //$save_path = __DIR__.'/private/sessions'; + $handler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler($save_path); - return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([], $handler); - }, - ], + return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([], $handler); + }, ], ], 'Filegator\Services\Cors\Cors' => [ diff --git a/docs/configuration/logging.md b/docs/configuration/logging.md index 5421217..1e6a7cd 100644 --- a/docs/configuration/logging.md +++ b/docs/configuration/logging.md @@ -21,4 +21,4 @@ Default handler will use simple ```/private/logs/app.log``` file to store applic ], ``` -There are many different handlers you can use. Some of them are listed [here](https://github.com/Seldaek/monolog#documentation). +There are many different handlers you can add ot top of the stack (monolog_handlers array). Some of them are listed [here](https://github.com/Seldaek/monolog#documentation). diff --git a/docs/configuration/session.md b/docs/configuration/session.md index 6cb0e10..c1bfb7e 100644 --- a/docs/configuration/session.md +++ b/docs/configuration/session.md @@ -18,16 +18,13 @@ Then, open ```configuration.php``` and update Session handler to: 'Filegator\Services\Session\SessionStorageInterface' => [ 'handler' => '\Filegator\Services\Session\Adapters\SessionStorage', 'config' => [ - 'session_handler' => 'database', - 'available' => [ - 'database' => function () { - $handler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler( + 'handler' => function () { + $handler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler( 'mysql://root:password@localhost:3360/filegator' - ); + ); - return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([], $handler); - }, - ], + return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([], $handler); + }, ], ], @@ -43,18 +40,15 @@ For example you can pass ```cookie_lifetime``` parameter to extend default sessi 'Filegator\Services\Session\SessionStorageInterface' => [ 'handler' => '\Filegator\Services\Session\Adapters\SessionStorage', 'config' => [ - 'session_handler' => 'database', - 'available' => [ - 'database' => function () { - $handler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler( + 'handler' => function () { + $handler = new \Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler( 'mysql://root:password@localhost:3360/filegator' - ); + ); - return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([ + return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage([ 'cookie_lifetime' => 365 * 24 * 60 * 60, // one year - ], $handler); - }, - ], + ], $handler); + }, ], ], diff --git a/tests/backend/Unit/Auth/AuthTest.php b/tests/backend/Unit/Auth/AuthTest.php index 9258b34..9021133 100644 --- a/tests/backend/Unit/Auth/AuthTest.php +++ b/tests/backend/Unit/Auth/AuthTest.php @@ -25,12 +25,9 @@ abstract class AuthTest extends TestCase { $this->session = new SessionStorage(new Request()); $this->session->init([ - 'session_handler' => 'mockfilesession', - 'available' => [ - 'mockfilesession' => function () { - return new \Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage(); - }, - ], + 'handler' => function () { + return new \Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage(); + }, ]); $this->setAuth(); diff --git a/tests/backend/Unit/SessionStorageTest.php b/tests/backend/Unit/SessionStorageTest.php index bc25585..7dc1b8d 100644 --- a/tests/backend/Unit/SessionStorageTest.php +++ b/tests/backend/Unit/SessionStorageTest.php @@ -25,12 +25,9 @@ class SessionStorageTest extends TestCase { $this->session_service = new SessionStorage(new Request()); $this->session_service->init([ - 'session_handler' => 'mockfilesession', - 'available' => [ - 'mockfilesession' => function () { - return new \Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage(); - }, - ], + 'handler' => function () { + return new \Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage(); + }, ]); parent::setUp(); diff --git a/tests/backend/configuration.php b/tests/backend/configuration.php index 803fb3c..be832ee 100644 --- a/tests/backend/configuration.php +++ b/tests/backend/configuration.php @@ -28,12 +28,9 @@ return [ 'Filegator\Services\Session\SessionStorageInterface' => [ 'handler' => '\Filegator\Services\Session\Adapters\SessionStorage', 'config' => [ - 'session_handler' => 'mockfilesession', - 'available' => [ - 'mockfilesession' => function () { - return new \Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage(); - }, - ], + 'handler' => function () { + return new \Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage(); + }, ], ], 'Filegator\Services\Tmpfs\TmpfsInterface' => [