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