BaseStore::getKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SilverStripe\HybridSessions\Store;
4
5
use SessionHandlerInterface;
6
use SilverStripe\ORM\FieldType\DBDatetime;
7
use SilverStripe\Core\Config\Configurable;
8
9
abstract class BaseStore implements SessionHandlerInterface
10
{
11
    use Configurable;
12
13
    /**
14
     * Session secret key
15
     *
16
     * @var string
17
     */
18
    protected $key = null;
19
20
    /**
21
     * Assign a new session secret key
22
     *
23
     * @param string $key
24
     */
25
    public function setKey($key)
26
    {
27
        $this->key = $key;
28
    }
29
30
    /**
31
     * Get the session secret key
32
     *
33
     * @return string
34
     */
35
    protected function getKey()
36
    {
37
        return $this->key;
38
    }
39
40
    /**
41
     * Get lifetime in number of seconds
42
     *
43
     * @return int
44
     */
45
    protected function getLifetime()
46
    {
47
        $params = session_get_cookie_params();
48
        $cookieLifetime = (int)$params['lifetime'];
49
        $gcLifetime = (int)ini_get('session.gc_maxlifetime');
50
51
        return $cookieLifetime ? min($cookieLifetime, $gcLifetime) : $gcLifetime;
52
    }
53
54
    /**
55
     * Gets the current unix timestamp
56
     *
57
     * @return int
58
     */
59
    protected function getNow()
60
    {
61
        return (int) DBDatetime::now()->getTimestamp();
62
    }
63
}
64