Passed
Push — master ( 8be542...031438 )
by Alexander
10:57
created

SessionProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 5 1
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\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
    public function register(Container $container): void
27
    {
28
        $container->set(SessionInterface::class, function () {
29
30
            return new Session($this->sessionOptions, $this->sessionHandler);
31
        });
32
    }
33
}
34