Completed
Push — master ( 615c5e...3a4e35 )
by Márk
04:34
created

CacheSessionHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Nofw\Session;
4
5
use Psr\Cache\CacheItemPoolInterface;
6
7
/**
8
 * PSR-6 Session handler implementation.
9
 *
10
 * @author Márk Sági-Kazár <[email protected]>
11
 */
12
final class CacheSessionHandler implements \SessionHandlerInterface
13
{
14
    /**
15
     * @var CacheItemPoolInterface
16
     */
17
    private $pool;
18
19
    /**
20
     * @param CacheItemPoolInterface $pool
21
     */
22 11
    public function __construct(CacheItemPoolInterface $pool)
23
    {
24 11
        $this->pool = $pool;
25 11
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 1
    public function close()
31
    {
32 1
        return true;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 2
    public function destroy($session_id)
39
    {
40 2
        return $this->pool->deleteItem($session_id);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 1
    public function gc($maxlifetime)
47
    {
48 1
        return true;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    public function open($save_path, $name)
55
    {
56 1
        return true;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 2
    public function read($session_id)
63
    {
64 2
        $item = $this->pool->getItem($session_id);
65
66 2
        if ($item->isHit()) {
67 1
            return $item->get();
68
        }
69
70 1
        return '';
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76 2
    public function write($session_id, $session_data)
77
    {
78 2
        $item = $this->pool->getItem($session_id);
79
80 2
        $item->set($session_data);
81
82 2
        return $this->pool->save($item);
83
    }
84
}
85