forked from parse-community/parse-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParseSessionStorage.php
More file actions
70 lines (58 loc) · 1.31 KB
/
Copy pathParseSessionStorage.php
File metadata and controls
70 lines (58 loc) · 1.31 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
<?php
namespace Parse;
/**
* ParseSessionStorage - Uses PHP session support for persistent storage.
*
* @package Parse
* @author Fosco Marotto <fjm@fb.com>
*/
class ParseSessionStorage implements ParseStorageInterface
{
/**
* @var string Parse will store its values in a specific key.
*/
private $storageKey = 'parseData';
public function __construct()
{
if (session_status() !== PHP_SESSION_ACTIVE) {
throw new ParseException(
'PHP session_start() must be called first.'
);
}
if (!isset($_SESSION[$this->storageKey])) {
$_SESSION[$this->storageKey] = array();
}
}
public function set($key, $value)
{
$_SESSION[$this->storageKey][$key] = $value;
}
public function remove($key)
{
unset($_SESSION[$this->storageKey][$key]);
}
public function get($key)
{
if (isset($_SESSION[$this->storageKey][$key])) {
return $_SESSION[$this->storageKey][$key];
}
return null;
}
public function clear()
{
$_SESSION[$this->storageKey] = array();
}
public function save()
{
// No action required. PHP handles persistence for $_SESSION.
return;
}
public function getKeys()
{
return array_keys($_SESSION[$this->storageKey]);
}
public function getAll()
{
return $_SESSION[$this->storageKey];
}
}