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

SessionProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
rs 10
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