Completed
Branch 2.x (03096d)
by Julián
08:36
created

Memcached::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * sessionware (https://github.com/juliangut/sessionware).
5
 * PSR7 session management middleware.
6
 *
7
 * @license BSD-3-Clause
8
 * @link https://github.com/juliangut/sessionware
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Jgut\Sessionware\Handler;
15
16
/**
17
 * Memcached session handler.
18
 */
19
class Memcached implements Handler
20
{
21
    use HandlerTrait;
22
23
    /**
24
     * @var \Memcached
25
     */
26
    protected $driver;
27
28
    /**
29
     * Memcached session handler constructor.
30
     *
31
     * @param \Memcached $driver
32
     */
33
    public function __construct(\Memcached $driver)
34
    {
35
        $this->driver = $driver;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     *
41
     * @throws \RuntimeException
42
     *
43
     * @SuppressWarnings(PMD.UnusedFormalParameter)
44
     */
45
    public function open($savePath, $sessionName)
46
    {
47
        $this->testConfiguration();
48
49
        return true;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function close()
56
    {
57
        return true;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function read($sessionId)
64
    {
65
        return $this->driver->get($sessionId) ?: '';
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function write($sessionId, $sessionData)
72
    {
73
        return $this->driver->set($sessionId, $sessionData, time() + $this->configuration->getLifetime());
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function destroy($sessionId)
80
    {
81
        return $this->driver->delete($sessionId);
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     *
87
     * @SuppressWarnings(PMD.ShortMethodName)
88
     * @SuppressWarnings(PMD.UnusedFormalParameter)
89
     */
90
    public function gc($maxLifetime)
91
    {
92
        return true;
93
    }
94
}
95