Skip to content

Commit 447a673

Browse files
Merge pull request #8 from AidynMakhataev/dev
Conditional binding session driver
2 parents 64bc69e + e86f55e commit 447a673

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/SessionServiceProvider.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
final class SessionServiceProvider extends ServiceProvider
1717
{
18+
public const DRIVER_NAME = 'tarantool';
19+
1820
public function register(): void
1921
{
2022
$this->mergeConfigFrom(
@@ -34,20 +36,22 @@ public function boot(): void
3436
], 'tarantool-session-config');
3537
}
3638

37-
$this->app->singleton(TarantoolSessionHandler::class, static function (Application $app) {
38-
$options = $app['config']['tarantool-session'];
39+
if ($this->app['config']['session']['driver'] === self::DRIVER_NAME) {
40+
$this->app->singleton(TarantoolSessionHandler::class, static function (Application $app) {
41+
$options = $app['config']['tarantool-session'];
3942

40-
$client = Client::fromOptions([
41-
'uri' => $options['host'],
42-
'username' => $options['user'],
43-
'password' => $options['password'],
44-
]);
43+
$client = Client::fromOptions([
44+
'uri' => $options['host'],
45+
'username' => $options['user'],
46+
'password' => $options['password'],
47+
]);
4548

46-
return new TarantoolSessionHandler($client, $options['space']);
47-
});
49+
return new TarantoolSessionHandler($client, $options['space']);
50+
});
4851

49-
Session::extend('tarantool', static function (Application $app) {
50-
return $app->make(TarantoolSessionHandler::class);
51-
});
52+
Session::extend(self::DRIVER_NAME, static function (Application $app) {
53+
return $app->make(TarantoolSessionHandler::class);
54+
});
55+
}
5256
}
5357
}

0 commit comments

Comments
 (0)