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

DoctrineCacheSessionHandler   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 63
ccs 15
cts 15
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A close() 0 4 1
A destroy() 0 4 1
A gc() 0 4 1
A open() 0 4 1
A read() 0 4 1
A write() 0 4 1
1
<?php
2
3
namespace Nofw\Session;
4
5
use Doctrine\Common\Cache\Cache;
6
7
/**
8
 * Doctrine Cache Session handler implementation.
9
 *
10
 * @author Márk Sági-Kazár <[email protected]>
11
 */
12
final class DoctrineCacheSessionHandler implements \SessionHandlerInterface
13
{
14
    /**
15
     * @var Cache
16
     */
17
    private $cache;
18
19
    /**
20
     * @param Cache $cache
21
     */
22 11
    public function __construct(Cache $cache)
23
    {
24 11
        $this->cache = $cache;
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->cache->delete($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
        return (string) $this->cache->fetch($session_id);
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 2
    public function write($session_id, $session_data)
71
    {
72 2
        return $this->cache->save($session_id, $session_data);
73
    }
74
}
75