-
Notifications
You must be signed in to change notification settings - Fork 0
/
Session.php
189 lines (169 loc) · 4.28 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
/**
* Create and manage sessions in easy and fast manner.
* Includes expiration hops and automatic expiration time reset
* on page loads.
*
* @copyright 2010 Artur Gajewski
* @license http://framework.zend.com/license BSD License
* @version Release: @package_version@
* @link http://ztools.arturgajewski.com
* @since Class available since Release 1.2.1
*/
class Ztools_Session
{
/**
* Name of the namespace for the session object
* @var
*/
private $namespace;
/**
* Expiration time of given session namespace in seconds
* @var
*/
private $expiration;
/**
* Expiration hops of given session namespace in seconds
* If this value is set, it will override the expiration date
* even if it it set as well.
* @var
*/
private $hops;
/**
* Constructor method for this class
* @param
*/
public function __construct( $namespace = null )
{
if ($namespace == null) {
$this->namespace = 'defaultNamespace';
} else {
$this->namespace = $namespace;
}
$this->timestamp = time();
$this->expiration = 3600; // Default expiration of one hour
}
/**
* Setter for session namespace
* @param $value
* @return $this
*/
function setNamespace( $value )
{
$this->namespace = $value;
return $this;
}
/**
* Getter for session namespace
* @return $this->sessionNamespace
*/
function getNamespace()
{
return $this->namespace;
}
/**
* Setter for session expiration time
* @param $value
* @return $this
*/
function setExpiration( $value )
{
$this->expiration = $value;
return $this;
}
/**
* Getter for session namespace
* @return $this->expirationTime
*/
function getExpiration()
{
return $this->expiration;
}
/**
* Setter for session expiration hops
* @param $value
* @return $this
*/
function setHops( $value )
{
$this->hops = $value;
return $this;
}
/**
* Getter for session expiration hops
* @return $this->hops
*/
function getHops()
{
return $this->hops;
}
/**
* Getter for session's start/refresh timestamp
* @return integer $session->timestamp
*/
function getTimestamp()
{
$session = new Zend_Session_Namespace( $this->getNamespace() );
return $session->timestamp;
}
/**
* Setter for session data container
* @param $value
*/
function setData( $value )
{
$session = new Zend_Session_Namespace( $this->getNamespace() );
$session->sessionData = $value;
return $this;
}
/**
* Getter for session data container
* @return $this->data
*/
function getData()
{
$session = new Zend_Session_Namespace( $this->getNamespace() );
return $session->sessionData;
}
/**
* Start the sessionw with given data
*/
function start()
{
$session = new Zend_Session_Namespace( $this->getNamespace() );
if ($this->getHops() != null && is_numeric($this->getHops())) {
$session->setExpirationHops( $this->getHops() );
} else {
$session->setExpirationSeconds( $this->getExpiration() );
}
$session->timestamp = time();
}
/**
* Check session if it is still actual and if it is, reset the expiration time
* If expiration hops is set, the expiration secods are ignored and not refreshed.
* If $reset is false, reset of timestamp will not occur.
* @param boolean $reset
* @return boolean
*/
function check( $reset = false )
{
$session = new Zend_Session_Namespace( $this->getNamespace() );
if ($session->timestamp) {
if ($this->getHops() == null) {
if ($reset == true) {
$session->timestamp = time();
$session->setExpirationSeconds( $this->getExpiration() );
}
}
return true;
}
return false;
}
/**
* End the session
*/
function end()
{
Zend_Session::namespaceUnset( $this->getNamespace() );
}
}