1 <?php
2
3 namespace Alo\Session;
4
5 use Alo;
6
7 if (!defined('GEN_START')) {
8 http_response_code(404);
9 } else {
10
11 /**
12 * Abstraction for cache-based session handlers
13 *
14 * @author Art <a.molcanovas@gmail.com>
15 */
16 abstract class AbstractCacheSession extends AbstractSession {
17
18 /**
19 * MemcachedWrapper instance
20 *
21 * @var Alo\Cache\MemcachedWrapper|Alo\Cache\RedisWrapper
22 */
23 protected $client;
24
25 /**
26 * Cache key prefix
27 *
28 * @var string
29 */
30 protected $prefix;
31
32 /**
33 * Destroys a session
34 *
35 * @author Art <a.molcanovas@gmail.com>
36 *
37 * @param string $sessionID The ID to destroy
38 *
39 * @return bool
40 */
41 public function destroy($sessionID) {
42 parent::destroy($sessionID);
43
44 return $this->client->delete($this->prefix . $sessionID);
45 }
46
47 /**
48 * Read ssession data
49 *
50 * @author Art <a.molcanovas@gmail.com>
51 * @link http://php.net/manual/en/sessionhandlerinterface.read.php
52 *
53 * @param string $sessionID The session id to read data for.
54 *
55 * @return string
56 */
57 public function read($sessionID) {
58 $data = $this->client->get($this->prefix . $sessionID);
59
60 return $data ? $data : '';
61 }
62
63 /**
64 * Write session data
65 *
66 * @author Art <a.molcanovas@gmail.com>
67 * @link http://php.net/manual/en/sessionhandlerinterface.write.php
68 *
69 * @param string $sessionID The session id.
70 * @param string $sessionData The encoded session data. This data is the
71 * result of the PHP internally encoding
72 * the $_SESSION superglobal to a serialized
73 * string and passing it as this parameter.
74 * Please note sessions use an alternative serialization method.
75 *
76 * @return bool
77 */
78 public function write($sessionID, $sessionData) {
79 return $this->client->set($this->prefix . $sessionID, $sessionData, ALO_SESSION_TIMEOUT);
80 }
81 }
82 }
83