1 <?php
2
3 namespace Alo\Session;
4
5 use Alo;
6 use Alo\Cache\MemcachedWrapper;
7 use Alo\Exception\LibraryException as Libex;
8
9 if (!defined('GEN_START')) {
10 http_response_code(404);
11 } else {
12
13 /**
14 * Memcached-based session handler
15 *
16 * @author Art <a.molcanovas@gmail.com>
17 */
18 class MemcachedSession extends AbstractCacheSession {
19
20 /**
21 * Constructor
22 *
23 * @author Art <a.molcanovas@gmail.com>
24 * @throws Libex When $instance is not passed and Alo::$cache does not contain a MemcachedWrapper instance
25 *
26 * @param MemcachedWrapper $instance If a parameter is passed here its instance will be used instead of Alo::$cache
27 */
28 function __construct(MemcachedWrapper &$instance = null) {
29 if ($instance) {
30 $this->client = &$instance;
31 } elseif (Alo::$cache && Alo::$cache instanceof MemcachedWrapper) {
32 $this->client = &Alo::$cache;
33 } else {
34 throw new Libex('MemcachedWrapper instance not found', Libex::E_REQUIRED_LIB_NOT_FOUND);
35 }
36
37 $this->prefix = ALO_SESSION_MC_PREFIX;
38
39 parent::__construct();
40 }
41
42 /**
43 * Initialises a Memcached session
44 *
45 * @author Art <a.molcanovas@gmail.com>
46 *
47 * @param MemcachedWrapper $dependcyObject If you don't want to use Alo::$db you can pass a MemcachedWrapper instance reference here.
48 */
49 static function init(MemcachedWrapper &$dependcyObject = null) {
50 parent::initSession($dependcyObject, get_class());
51 }
52 }
53 }
54