This repository was archived by the owner on Dec 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathSessionDataStore.php
More file actions
66 lines (59 loc) · 1.75 KB
/
SessionDataStore.php
File metadata and controls
66 lines (59 loc) · 1.75 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
<?php
namespace YousafSaqib\ConstantContact\Auth;
/**
* Example implementation of the CTCTDataStore interface that uses session for access token storage
*
* @package Auth
* @author Constant Contact
*/
class SessionDataStore implements CtctDataStore
{
public function __construct()
{
session_start();
if (!isset($_SESSION['datastore'])) {
$_SESSION['datastore'] = array();
}
}
/**
* Add a new user to the data store
* @param string $username - Constant Contact username
* @param array $params - additional parameters
*/
public function addUser($username, array $params)
{
$_SESSION['datastore'][$username] = $params;
}
/**
* Get an existing user from the data store
* @param string $username - Constant Contact username
* @return Array params of the username in the datastore, or false if the username doesn't exist
*/
public function getUser($username)
{
if (array_key_exists($username, $_SESSION['datastore'])) {
return $_SESSION['datastore'][$username];
} else {
return false;
}
}
/**
* Update an existing user in the data store
* @param string $username - Constant Contact username
* @param array $params - additional parameters
*/
public function updateUser($username, array $params)
{
if (array_key_exists($username, $_SESSION['datastore'])) {
$_SESSION['datastore'][$username] = $params;
}
}
/**
* Delete an existing user from the data store
* @param string $username - Constant Contact username
*/
public function deleteUser($username)
{
unset($_SESSION['datastore'][$username]);
}
}