Passed
Push — master ( 3c979b...72c793 )
by Kirill
03:02
created

SessionConfig::isSecure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Session\Config;
13
14
use Spiral\Core\Container\Autowire;
15
use Spiral\Core\InjectableConfig;
16
17
/**
18
 * SessionManager configuration.
19
 */
20
final class SessionConfig extends InjectableConfig
21
{
22
    public const CONFIG = 'session';
23
24
    /**
25
     * @var array
26
     */
27
    protected $config = [
28
        'lifetime' => 86400,
29
        'cookie'   => 'SID',
30
        'secure'   => false,
31
        'sameSite' => null,
32
        'handler'  => null,
33
        'handlers' => []
34
    ];
35
36
    /**
37
     * @return int
38
     */
39
    public function getLifetime(): int
40
    {
41
        return $this->config['lifetime'];
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getCookie(): string
48
    {
49
        return $this->config['cookie'];
50
    }
51
52
    /**
53
     * @return bool
54
     */
55
    public function isSecure(): bool
56
    {
57
        return $this->config['secure'] ?? false;
58
    }
59
60
    /**
61
     * Get handler autowire options.
62
     *
63
     * @return Autowire|null
64
     */
65
    public function getHandler(): ?Autowire
66
    {
67
        if (empty($this->config['handler'])) {
68
            return null;
69
        }
70
71
        if ($this->config['handler'] instanceof Autowire) {
72
            return $this->config['handler'];
73
        }
74
75
        if (class_exists($this->config['handler'])) {
76
            return new Autowire($this->config['handler']);
77
        }
78
79
        $handler = $this->config['handlers'][$this->config['handler']];
80
81
        return new Autowire($handler['class'], $handler['options']);
82
    }
83
84
    /**
85
     * @return string|null
86
     */
87
    public function getSameSite(): ?string
88
    {
89
        return $this->config['sameSite'] ?? null;
90
    }
91
}
92