|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Asylamba\Classes\Library\Session; |
|
4
|
|
|
|
|
5
|
|
|
use Asylamba\Classes\Redis\RedisManager; |
|
6
|
|
|
|
|
7
|
|
|
class SessionWrapper |
|
8
|
|
|
{ |
|
9
|
|
|
/** @var Session **/ |
|
10
|
|
|
protected $currentSession; |
|
11
|
|
|
/** @var RedisManager **/ |
|
12
|
|
|
protected $redisManager; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @param RedisManager $redisManager |
|
16
|
|
|
*/ |
|
17
|
|
|
public function __construct(RedisManager $redisManager) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->redisManager = $redisManager; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function setCurrentSession(Session $session) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->currentSession = $session; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function getCurrentSession() |
|
28
|
|
|
{ |
|
29
|
|
|
return $this->currentSession; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param int $sessionId |
|
34
|
|
|
* @return Session |
|
35
|
|
|
*/ |
|
36
|
|
|
public function createSession($sessionId) |
|
37
|
|
|
{ |
|
38
|
|
|
$session = new Session(); |
|
39
|
|
|
$session->add('session_id', $sessionId); |
|
40
|
|
|
|
|
41
|
|
|
$this->save($session); |
|
42
|
|
|
|
|
43
|
|
|
return $session; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function save(Session $session) |
|
47
|
|
|
{ |
|
48
|
|
|
$redisConnection = $this->redisManager->getConnection(); |
|
49
|
|
|
$redisConnection->set('session:' . $session->get('session_id'), serialize($session->getData())); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param string $sessionId |
|
54
|
|
|
* @return \Asylamba\Classes\Library\Session\Session |
|
55
|
|
|
*/ |
|
56
|
|
|
public function fetchSession($sessionId) |
|
57
|
|
|
{ |
|
58
|
|
|
if (($data = $this->redisManager->getConnection()->get('session:' . $sessionId)) === false) { |
|
59
|
|
|
return null; |
|
60
|
|
|
} |
|
61
|
|
|
$session = new Session(); |
|
62
|
|
|
$session->setData(unserialize($data)); |
|
63
|
|
|
return $session; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function clearWrapper() |
|
67
|
|
|
{ |
|
68
|
|
|
if ($this->currentSession !== null) { |
|
69
|
|
|
$this->save($this->currentSession); |
|
70
|
|
|
} |
|
71
|
|
|
$this->currentSession = null; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function add($key, $value) |
|
75
|
|
|
{ |
|
76
|
|
|
if ($this->currentSession === null) { |
|
77
|
|
|
return null; |
|
78
|
|
|
} |
|
79
|
|
|
return $this->currentSession->add($key, $value); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function addBase($key, $id, $name, $sector, $system, $img, $type) |
|
83
|
|
|
{ |
|
84
|
|
|
if ($this->currentSession === null) { |
|
85
|
|
|
return null; |
|
86
|
|
|
} |
|
87
|
|
|
return $this->currentSession->addBase($key, $id, $name, $sector, $system, $img, $type); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function addFlashbag($message, $type) |
|
91
|
|
|
{ |
|
92
|
|
|
if ($this->currentSession === null) { |
|
93
|
|
|
return null; |
|
94
|
|
|
} |
|
95
|
|
|
return $this->currentSession->addFlashbag($message, $type); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function addHistory($path) |
|
99
|
|
|
{ |
|
100
|
|
|
if ($this->currentSession === null) { |
|
101
|
|
|
return null; |
|
102
|
|
|
} |
|
103
|
|
|
return $this->currentSession->addHistory($path); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function all() |
|
107
|
|
|
{ |
|
108
|
|
|
if ($this->currentSession === null) { |
|
109
|
|
|
return []; |
|
110
|
|
|
} |
|
111
|
|
|
return $this->currentSession->all(); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function baseExist($id) |
|
115
|
|
|
{ |
|
116
|
|
|
if ($this->currentSession === null) { |
|
117
|
|
|
return false; |
|
118
|
|
|
} |
|
119
|
|
|
return $this->currentSession->baseExist($id); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function clear() |
|
123
|
|
|
{ |
|
124
|
|
|
if ($this->currentSession === null) { |
|
125
|
|
|
return null; |
|
126
|
|
|
} |
|
127
|
|
|
return $this->currentSession->clear(); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function destroy() |
|
131
|
|
|
{ |
|
132
|
|
|
if ($this->currentSession === null) { |
|
133
|
|
|
return null; |
|
134
|
|
|
} |
|
135
|
|
|
return $this->currentSession->destroy(); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function exist($key) |
|
139
|
|
|
{ |
|
140
|
|
|
if ($this->currentSession === null) { |
|
141
|
|
|
return false; |
|
142
|
|
|
} |
|
143
|
|
|
return $this->currentSession->exist($key); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function flushFlashbags() |
|
147
|
|
|
{ |
|
148
|
|
|
if ($this->currentSession === null) { |
|
149
|
|
|
return null; |
|
150
|
|
|
} |
|
151
|
|
|
return $this->currentSession->flushFlashbags(); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
public function getFlashbags() |
|
155
|
|
|
{ |
|
156
|
|
|
if ($this->currentSession === null) { |
|
157
|
|
|
return []; |
|
158
|
|
|
} |
|
159
|
|
|
return $this->currentSession->getFlashbags(); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
public function getHistory() |
|
163
|
|
|
{ |
|
164
|
|
|
if ($this->currentSession === null) { |
|
165
|
|
|
return []; |
|
166
|
|
|
} |
|
167
|
|
|
return $this->currentSession->getHistory(); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
public function getLastHistory() |
|
171
|
|
|
{ |
|
172
|
|
|
if ($this->currentSession === null) { |
|
173
|
|
|
return null; |
|
174
|
|
|
} |
|
175
|
|
|
return $this->currentSession->getLastHistory(); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
public function getLifetime() |
|
179
|
|
|
{ |
|
180
|
|
|
if ($this->currentSession === null) { |
|
181
|
|
|
return 0; |
|
182
|
|
|
} |
|
183
|
|
|
return $this->currentSession->getLifetime(); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
public function initLastUpdate() |
|
187
|
|
|
{ |
|
188
|
|
|
if ($this->currentSession === null) { |
|
189
|
|
|
return null; |
|
190
|
|
|
} |
|
191
|
|
|
return $this->currentSession->initLastUpdate(); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
public function initPlayerBase() |
|
195
|
|
|
{ |
|
196
|
|
|
if ($this->currentSession === null) { |
|
197
|
|
|
return null; |
|
198
|
|
|
} |
|
199
|
|
|
return $this->currentSession->initPlayerBase(); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
public function initPlayerBonus() |
|
203
|
|
|
{ |
|
204
|
|
|
if ($this->currentSession === null) { |
|
205
|
|
|
return null; |
|
206
|
|
|
} |
|
207
|
|
|
return $this->currentSession->initPlayerBonus(); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
public function initPlayerEvent() |
|
211
|
|
|
{ |
|
212
|
|
|
if ($this->currentSession === null) { |
|
213
|
|
|
return null; |
|
214
|
|
|
} |
|
215
|
|
|
return $this->currentSession->initPlayerEvent(); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
public function initPlayerInfo() |
|
219
|
|
|
{ |
|
220
|
|
|
if ($this->currentSession === null) { |
|
221
|
|
|
return null; |
|
222
|
|
|
} |
|
223
|
|
|
return $this->currentSession->initPlayerInfo(); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
public function remove($key) |
|
227
|
|
|
{ |
|
228
|
|
|
if ($this->currentSession === null) { |
|
229
|
|
|
return null; |
|
230
|
|
|
} |
|
231
|
|
|
return $this->currentSession->remove($key); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
public function removeBase($key, $id) |
|
235
|
|
|
{ |
|
236
|
|
|
if ($this->currentSession === null) { |
|
237
|
|
|
return null; |
|
238
|
|
|
} |
|
239
|
|
|
return $this->currentSession->removeBase($key, $id); |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
public function get($key) |
|
243
|
|
|
{ |
|
244
|
|
|
if ($this->currentSession === null) { |
|
245
|
|
|
return null; |
|
246
|
|
|
} |
|
247
|
|
|
return $this->currentSession->get($key); |
|
248
|
|
|
} |
|
249
|
|
|
} |