Total Complexity | 13 |
Total Lines | 70 |
Duplicated Lines | 0 % |
Coverage | 86.49% |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
6 | class Session extends Service implements Interfaces\ISession |
||
7 | { |
||
8 | protected $parametersList = ['type']; |
||
9 | private static $container; |
||
10 | |||
11 | |||
12 | 5 | protected function init() |
|
13 | { |
||
14 | 5 | if (self::$container === null) { |
|
15 | 2 | switch ($this->type) { |
|
|
|||
16 | 2 | case 'native': |
|
17 | 1 | self::$container = Suricate::SessionNative(true); |
|
18 | 1 | break; |
|
19 | 1 | case 'cookie': |
|
20 | self::$container = Suricate::SessionCookie(true); |
||
21 | break; |
||
22 | 1 | case 'memcache': |
|
23 | self::$container = Suricate::SessionMemcache(true); |
||
24 | break; |
||
25 | 1 | case 'none': |
|
26 | break; |
||
27 | default: |
||
28 | 1 | throw new Exception("Unknown session type " . $this->type); |
|
29 | } |
||
30 | } |
||
31 | 4 | } |
|
32 | |||
33 | /** |
||
34 | * Get instance of session driver used |
||
35 | * @return Sessiondriver instance |
||
36 | */ |
||
37 | 1 | public function getInstance() |
|
38 | { |
||
39 | 1 | $this->init(); |
|
40 | 1 | return self::$container; |
|
41 | } |
||
42 | |||
43 | 1 | public function getId() |
|
44 | { |
||
45 | 1 | $this->init(); |
|
46 | 1 | return self::$container->getId(); |
|
47 | } |
||
48 | 1 | public function regenerate() |
|
49 | { |
||
50 | 1 | $this->init(); |
|
51 | 1 | return self::$container->regenerate(); |
|
52 | } |
||
53 | |||
54 | 5 | public function read($key) |
|
55 | { |
||
56 | 5 | $this->init(); |
|
57 | 4 | return self::$container->read($key); |
|
58 | } |
||
59 | |||
60 | 4 | public function write($key, $data) |
|
64 | } |
||
65 | |||
66 | 4 | public function destroy($key) |
|
70 | } |
||
71 | |||
72 | 1 | public function close() |
|
73 | { |
||
74 | 1 | $this->init(); |
|
76 | } |
||
77 | } |
||
78 |