Session::store()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace evelikto\di\storage\impl;
4
use evelikto\di\storage\OfflineStorage;
5
6
/** Session storage implementation */
7
class Session implements OfflineStorage
8
{
9
    /** Just ensure the preconditions - session is active and started */
10
    public function __construct() {
11
        if (session_status() === PHP_SESSION_NONE)
12
            session_start();
13
        else if (session_status() === PHP_SESSION_DISABLED)
14
            throw new SessionsNotEnabled();
15
    }
16
17
    /** {@inheritdoc} */
18
    public function fetch(string $key) {
19
        return isset($_SESSION[$key]) ? unserialize($_SESSION[$key]) : null;
20
    }
21
22
    /** {@inheritdoc} */
23
    public function store(string $key, $value) {
24
        $_SESSION[$key] = serialize($value);
25
    }
26
}