Session   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A set() 0 4 1
A get() 0 8 2
A del() 0 4 1
A destroy() 0 5 1
A getInstance() 0 9 2
1
<?php
2
3
namespace XoopsModules\Xnewsletter;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
/**
15
 *  Session class
16
 *
17
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
18
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
19
 * @package         xnewsletter
20
 * @since           1.3
21
 * @author          trabis <[email protected]>
22
 * @author          Harry Fuecks (PHP Anthology Volume II)
23
 */
24
require_once dirname(__DIR__) . '/include/common.php';
25
26
/**
27
 * Class Session
28
 */
29
class Session
30
{
31
    /**
32
     * Session constructor<br>
33
     * Starts the session with session_start()
34
     * <strong>Note:</strong> that if the session has already started,
35
     * session_start() does nothing
36
     */
37
    protected function __construct()
38
    {
39
        if (false === @session_start()) {
40
            throw new \RuntimeException('Session could not start.');
41
        }
42
    }
43
44
    /**
45
     * Sets a session variable
46
     *
47
     * @param string $name  name of variable
48
     * @param mixed  $value value of variable
49
     *
50
     * @access public
51
     */
52
    public function set($name, $value)
53
    {
54
        $_SESSION[$name] = $value;
55
    }
56
57
    /**
58
     * Fetches a session variable
59
     *
60
     * @param string $name name of variable
61
     *
62
     * @return mixed value of session variable
63
     * @access public
64
     */
65
    public function get($name)
66
    {
67
        if (isset($_SESSION[$name])) {
68
            return $_SESSION[$name];
69
        }
70
71
        return false;
72
    }
73
74
    /**
75
     * Deletes a session variable
76
     *
77
     * @param string $name name of variable
78
     *
79
     * @access public
80
     */
81
    public function del($name)
82
    {
83
        unset($_SESSION[$name]);
84
    }
85
86
    /**
87
     * Destroys the whole session
88
     *
89
     * @access public
90
     */
91
    public function destroy()
92
    {
93
        $_SESSION = [];
94
        session_destroy();
95
    }
96
97
    /**
98
     * @return Session
99
     */
100
    public static function getInstance()
101
    {
102
        static $instance;
103
        if (null === $instance) {
104
            $instance = new static();
105
        }
106
107
        return $instance;
108
    }
109
}
110