Completed
Push — master ( bbe443...f4a6ec )
by Tim
24:42 queued 09:39
created

SessionService::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
/**
3
 * Session Service
4
 *
5
 * @package Html5videoplayerPowermail\Service
6
 * @author  Tim Lochmüller
7
 */
8
9
namespace HVP\Html5videoplayerPowermail\Service;
10
11
/**
12
 * Session Service
13
 *
14
 * @author Tim Lochmüller
15
 */
16
class SessionService extends AbstractService
17
{
18
19
    /**
20
     * Check if the value exists
21
     *
22
     * @param string $name
23
     *
24
     * @return boolean
25
     */
26
    public function has($name)
27
    {
28
        return isset($_COOKIE[$name]);
29
    }
30
31
    /**
32
     * Get a vaukue
33
     *
34
     * @param string $name
35
     *
36
     * @return mixed|null
37
     */
38
    public function get($name)
39
    {
40
        if (!$this->has($name)) {
41
            return null;
42
        }
43
        return unserialize($_COOKIE[$name]);
44
45
    }
46
47
    /**
48
     * Set a value
49
     *
50
     * @param string $name
51
     * @param mixed  $value
52
     *
53
     * @return void
54
     */
55
    public function set($name, $value)
56
    {
57
        $setValue = serialize($value);
58
        setcookie($name, $setValue, null, '/');
59
        $_COOKIE[$name] = $setValue;
60
    }
61
}
62