Completed
Push — master ( e15c58...b150a8 )
by Changwan
07:08
created

HttpServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 1
b 0
f 1
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')));
0 ignored issues
show
Bug introduced by
It seems like \Wandu\Foundation\path(\...th', 'cache/sessions')) targeting Wandu\Foundation\path() can also be of type array; however, Wandu\Http\Session\Handl...eHandler::__construct() does only seem to accept string, maybe add an additional type check?

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.

Loading history...
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