1 | <?php |
||
13 | class FlipSession extends Singleton |
||
14 | { |
||
15 | /** |
||
16 | * Does the variable exist in the session |
||
17 | * |
||
18 | * @SuppressWarnings(PHPMD.Superglobals) |
||
19 | */ |
||
20 | static function doesVarExist($name) |
||
|
|||
21 | { |
||
22 | return isset($_SESSION[$name]); |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * Get a variable from the session |
||
27 | * |
||
28 | * @SuppressWarnings(PHPMD.Superglobals) |
||
29 | */ |
||
30 | static function getVar($name, $default = false) |
||
31 | { |
||
32 | if(FlipSession::doesVarExist($name)) |
||
33 | { |
||
34 | return $_SESSION[$name]; |
||
35 | } |
||
36 | else |
||
37 | { |
||
38 | return $default; |
||
39 | } |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Set a variable in the session |
||
44 | * |
||
45 | * @SuppressWarnings(PHPMD.Superglobals) |
||
46 | */ |
||
47 | static function setVar($name, $value) |
||
48 | { |
||
49 | $_SESSION[$name] = $value; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Is a user currently logged in? |
||
54 | * |
||
55 | * @SuppressWarnings(PHPMD.Superglobals) |
||
56 | */ |
||
57 | static function isLoggedIn() |
||
58 | { |
||
59 | if(isset($_SESSION['flipside_user'])) |
||
60 | { |
||
61 | return true; |
||
62 | } |
||
63 | else if(isset($_SESSION['AuthMethod']) && isset($_SESSION['AuthData'])) |
||
64 | { |
||
65 | $auth = AuthProvider::getInstance(); |
||
66 | return $auth->isLoggedIn($_SESSION['AuthData'], $_SESSION['AuthMethod']); |
||
67 | } |
||
68 | else |
||
69 | { |
||
70 | return false; |
||
71 | } |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Get the currently logged in user |
||
76 | * |
||
77 | * @SuppressWarnings(PHPMD.Superglobals) |
||
78 | */ |
||
79 | static function getUser() |
||
80 | { |
||
81 | if(isset($_SESSION['flipside_user'])) |
||
82 | { |
||
83 | return $_SESSION['flipside_user']; |
||
84 | } |
||
85 | else if(isset($_SESSION['AuthMethod']) && isset($_SESSION['AuthData'])) |
||
86 | { |
||
87 | $auth = AuthProvider::getInstance(); |
||
88 | $user = $auth->getUser($_SESSION['AuthData'], $_SESSION['AuthMethod']); |
||
89 | if($user !== null) |
||
90 | { |
||
91 | $_SESSION['flipside_user'] = $user; |
||
92 | } |
||
93 | return $user; |
||
94 | } |
||
95 | else |
||
96 | { |
||
97 | return null; |
||
98 | } |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Set the currently logged in user |
||
103 | * |
||
104 | * @SuppressWarnings(PHPMD.Superglobals) |
||
105 | */ |
||
106 | static function setUser($user) |
||
107 | { |
||
108 | $_SESSION['flipside_user'] = $user; |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Obtain the current users email address |
||
113 | * |
||
114 | * @SuppressWarnings(PHPMD.Superglobals) |
||
115 | */ |
||
116 | static function getUserEmail() |
||
117 | { |
||
118 | if(isset($_SESSION['flipside_email'])) |
||
119 | { |
||
120 | return $_SESSION['flipside_email']; |
||
121 | } |
||
122 | $user = FlipSession::getUser(); |
||
123 | if($user === false || $user === null) |
||
124 | { |
||
125 | return false; |
||
126 | } |
||
127 | if(isset($user->mail) && isset($user->mail[0])) |
||
128 | { |
||
129 | $_SESSION['flipside_email'] = $user->mail[0]; |
||
130 | return $_SESSION['flipside_email']; |
||
131 | } |
||
132 | return false; |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * This will end your session |
||
137 | * |
||
138 | * @SuppressWarnings(PHPMD.Superglobals) |
||
139 | */ |
||
140 | static function end() |
||
141 | { |
||
142 | if(isset($_SESSION) && !empty($_SESSION)) |
||
143 | { |
||
144 | $_SESSION = array(); |
||
145 | session_destroy(); |
||
146 | } |
||
147 | } |
||
148 | |||
149 | static function unserializePhpSession($sessionData) |
||
167 | |||
168 | static function getAllSessions() |
||
169 | { |
||
170 | $res = array(); |
||
171 | $sessFiles = scandir(ini_get('session.save_path')); |
||
172 | $count = count($sessFiles); |
||
173 | for($i = 0; $i < $count; $i++) |
||
174 | { |
||
175 | if($sessFiles[$i][0] === '.') |
||
198 | |||
199 | static function getSessionById($sid) |
||
204 | |||
205 | static function deleteSessionById($sid) |
||
209 | } |
||
210 | /* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
||
212 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.