-
Notifications
You must be signed in to change notification settings - Fork 0
/
Session.php
73 lines (54 loc) · 1.86 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
<?php
require_once('./core/MiddleWare.php');
require_once('./core/Request.php');
class Session extends MiddleWare {
private $_settings;
public function __construct(
int $lifeTime = 3600,
string $path = '/',
string $domain = null,
bool $secure = false,
bool $httpOnly = false
) {
$this->_settings['name'] = 'fleshpress_session';
$this->_settings['lifeTime'] = $lifeTime;
$this->_settings['path'] = $path;
$this->_settings['domain'] = $domain;
$this->_settings['secure'] = $secure;
$this->_settings['httpOnly'] = $httpOnly;
}
public function __invoke(Request $req)
{
session_set_cookie_params(
$this->_settings['lifeTime'],
$this->_settings['path'],
$this->_settings['domain'],
$this->_settings['secure'],
$this->_settings['httpOnly']
);
session_name($this->_settings['name']);
session_start();
}
public function __set($name, $value)
{
$_SESSION[$this->_settings['name']][$name] = $value;
}
public function __get($name)
{
if (! empty($_SESSION[$this->_settings['name']])) {
if (array_key_exists($name, $_SESSION[$this->_settings['name']])) {
return $_SESSION[$this->_settings['name']][$name];
}
}
return null;
}
public function __isset($name)
{
return isset($_SESSION[$this->_settings['name']][$name]);
}
public function __unset($name)
{
unset($_SESSION[$this->_settings['name']][$name]);
}
}
?>