1: <?php
2: namespace Ctct\Auth;
3:
4: /**
5: * Example implementation of the CTCTDataStore interface that uses session for access token storage
6: *
7: * @package Auth
8: * @author Constant Contact
9: */
10: class SessionDataStore implements CtctDataStore
11: {
12: public function __construct()
13: {
14: session_start();
15:
16: if (!isset($_SESSION['datastore'])) {
17: $_SESSION['datastore'] = array();
18: }
19:
20: }
21:
22: /**
23: * Add a new user to the data store
24: * @param string $username - Constant Contact username
25: * @param array $params - additional parameters
26: */
27: public function addUser($username, array $params)
28: {
29: $_SESSION['datastore'][$username] = $params;
30: }
31:
32: /**
33: * Get an existing user from the data store
34: * @param string $username - Constant Contact username
35: * @return Array params of the username in the datastore, or false if the username doesn't exist
36: */
37: public function getUser($username)
38: {
39: if (array_key_exists($username, $_SESSION['datastore'])) {
40: return $_SESSION['datastore'][$username];
41: } else {
42: return false;
43: }
44: }
45:
46: /**
47: * Update an existing user in the data store
48: * @param string $username - Constant Contact username
49: * @param array $params - additional parameters
50: */
51: public function updateUser($username, array $params)
52: {
53: if (array_key_exists($username, $_SESSION['datastore'])) {
54: $_SESSION['datastore'][$username] = $params;
55: }
56: }
57:
58: /**
59: * Delete an existing user from the data store
60: * @param string $username - Constant Contact username
61: */
62: public function deleteUser($username)
63: {
64: unset($_SESSION['datastore'][$username]);
65: }
66: }
67: