Passed
Pull Request — master (#261)
by Wilmer
14:46
created

SessionProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Web\Provider;
6
7
use SessionHandlerInterface;
8
use Yiisoft\Di\Container;
9
use Yiisoft\Di\Support\ServiceProvider;
10
use Yiisoft\Yii\Web\Session\Session;
11
use Yiisoft\Yii\Web\Session\SessionInterface;
12
13
final class SessionProvider extends ServiceProvider
14
{
15
    private array $sessionOptions;
16
    private ?SessionHandlerInterface $sessionHandler;
17
18
    public function __construct(
19
        array $sessionOptions = [['cookie_secure' => 0]],
20
        ?SessionHandlerInterface $sessionHandler = null
21
    ) {
22
        $this->sessionOptions = $sessionOptions;
23
        $this->sessionHandler = $sessionHandler;
24
    }
25
26
    /**
27
     * @suppress PhanAccessMethodProtected
28
     */
29
    public function register(Container $container): void
30
    {
31
        $container->set(SessionInterface::class, function () {
32
            return new Session($this->sessionOptions, $this->sessionHandler);
33
        });
34
    }
35
}
36