This repository has been archived by the owner on Mar 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
HttpServiceProvider.php
50 lines (47 loc) · 1.64 KB
/
HttpServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace Wandu\Http;
use Predis\Client;
use SessionHandlerInterface;
use Wandu\Config\Contracts\Config;
use Wandu\DI\ContainerInterface;
use Wandu\DI\ServiceProviderInterface;
use Wandu\Http\Factory\ResponseFactory;
use Wandu\Http\Session\Configuration;
use Wandu\Http\Session\Handler\FileHandler;
use Wandu\Http\Session\Handler\GlobalHandler;
use Wandu\Http\Session\Handler\RedisHandler;
class HttpServiceProvider implements ServiceProviderInterface
{
/**
* {@inheritdoc}
*/
public function register(ContainerInterface $app)
{
$app->closure(ResponseFactory::class, function () {
return response(); // singleton
});
$app->closure(Configuration::class, function (Config $config) {
return new Configuration([
'timeout' => $config->get('session.timeout', 3600),
'name' => $config->get('session.name', ini_get('session.name') ?: 'WdSessId'),
'gc_frequency' => $config->get('session.gc_frequency', 100),
]);
});
$app->closure(SessionHandlerInterface::class, function (Config $config, ContainerInterface $app) {
switch ($config->get('session.type')) {
case 'file':
return new FileHandler($config->get('session.path', 'cache/sessions'));
case 'redis':
return new RedisHandler($app[Client::class], $config->get('session.timeout', 3600));
default:
return new GlobalHandler();
}
});
}
/**
* {@inheritdoc}
*/
public function boot(ContainerInterface $app)
{
}
}