-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSession.php
More file actions
executable file
·106 lines (98 loc) · 1.9 KB
/
Copy pathSession.php
File metadata and controls
executable file
·106 lines (98 loc) · 1.9 KB
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
101
102
103
104
105
106
<?php
/**
*
* -+-----------------------------------
* |PHP5 Framework - 2011
* |Web Site: www.iblue.cc
* |E-mail: mejinke@gmail.com
* |Date: 2012-01-12
* -+-----------------------------------
*
* @desc session类
* @author jingke
*/
class XF_Session implements XF_Session_Interface
{
/**
* 默认会话命名空间
* @var string
*/
const NAMESPACE_DEFAULT = 'XF_MEMBER';
/**
* 当前会话命名空间
* @var string
*/
protected $_namespace;
/**
* 当前是否已上锁
* @var bool
*/
protected $_lock = FALSE;
/**
* 初始化session
* @param string $namespace 会话命名空间
*/
public function __construct($namespace = self::NAMESPACE_DEFAULT)
{
$namespace = (string) $namespace;
$this->_namespace = $namespace;
if (!isset($_SESSION[$this->_namespace]))
$_SESSION[$this->_namespace] = NULL;
}
/**
* session是否为空
* @return bool
*/
public function isEmpty()
{
if (isset($_SESSION[$this->_namespace]) && $_SESSION[$this->_namespace]!==null)
return false;
return true;
}
/**
* 写入内容
* @param mixed $content 内容
* @return XF_Session
*/
public function write($content)
{
if ($this->_lock == FALSE)
{
$this->_lock = TRUE;
if ($content === null && isset($_SESSION[$this->_namespace]))
unset($_SESSION[$this->_namespace]);
else
$_SESSION[$this->_namespace] = $content;
$this->_lock = FALSE;
}
return $this;
}
/**
* 销毁session
* @return XF_Session
*/
public function clear()
{
if (isset($_SESSION[$this->_namespace]))
unset($_SESSION[$this->_namespace]);
return $this;
}
/**
* 读取内容
* @return mixed
*/
public function read()
{
return $_SESSION[$this->_namespace];
}
/**
* 是否存在指定的内容
* @param string $key 键
* @return bool
*/
public function hasContent($key)
{
$key = (string) $key;
return isset($_SESSION[$this->_namespace][$key]);
}
}