1
|
|
|
<?php |
2
|
|
|
namespace Wandu\Http; |
3
|
|
|
|
4
|
|
|
use Predis\Client; |
5
|
|
|
use SessionHandlerInterface; |
6
|
|
|
use Wandu\DI\ContainerInterface; |
7
|
|
|
use Wandu\DI\ServiceProviderInterface; |
8
|
|
|
use Wandu\Http\Factory\ResponseFactory; |
9
|
|
|
use Wandu\Http\Session\Handler\FileHandler; |
10
|
|
|
use Wandu\Http\Session\Handler\GlobalHandler; |
11
|
|
|
use Wandu\Http\Session\Handler\RedisHandler; |
12
|
|
|
use Wandu\Http\Session\SessionFactory; |
13
|
|
|
use function Wandu\Foundation\config; |
14
|
|
|
use function Wandu\Foundation\path; |
15
|
|
|
|
16
|
|
|
class HttpServiceProvider implements ServiceProviderInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* {@inheritdoc} |
20
|
|
|
*/ |
21
|
|
|
public function register(ContainerInterface $app) |
22
|
|
|
{ |
23
|
|
|
$app->closure(ResponseFactory::class, function () { |
24
|
|
|
return response(); // singleton |
25
|
|
|
}); |
26
|
|
|
$app->closure(SessionFactory::class, function ($app) { |
27
|
|
|
return new SessionFactory($app[SessionHandlerInterface::class], [ |
28
|
|
|
'timeout' => config('session.timeout', 3600), |
29
|
|
|
'name' => config('session.name', ini_get('session.name') ?: 'WdSessId'), |
30
|
|
|
'gc_frequency' => config('session.gc_frequency', 100), |
31
|
|
|
]); |
32
|
|
|
}); |
33
|
|
|
$app->closure(SessionHandlerInterface::class, function ($app) { |
34
|
|
|
switch (config('session.type')) { |
35
|
|
|
case 'file': |
36
|
|
|
return new FileHandler(path(config('session.path', 'cache/sessions'))); |
|
|
|
|
37
|
|
|
case 'redis': |
38
|
|
|
return new RedisHandler($app[Client::class], config('session.timeout', 3600)); |
39
|
|
|
default: |
40
|
|
|
return new GlobalHandler(); |
41
|
|
|
} |
42
|
|
|
}); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
public function boot(ContainerInterface $app) |
49
|
|
|
{ |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.