Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
45.00% |
9 / 20 |
|
26.67% |
4 / 15 |
CRAP | |
0.00% |
0 / 1 |
SessionContainer | |
45.00% |
9 / 20 |
|
26.67% |
4 / 15 |
58.59 | |
0.00% |
0 / 1 |
fromContainer | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
setGroup | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
writeData | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
set | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getEntity | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
remove | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
clear | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
restart | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
clearGroup | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
has | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isEmpty | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getSession | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
loadSession | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace BO\Slim\Middleware\Session; |
4 | |
5 | class SessionContainer implements SessionInterface |
6 | { |
7 | private $sessionContainer; |
8 | |
9 | private $sessionLoader; |
10 | |
11 | public static function fromContainer(callable $sessionLoader) |
12 | { |
13 | $instance = new static(); |
14 | $instance->sessionLoader = $sessionLoader; |
15 | return $instance; |
16 | } |
17 | |
18 | public function setGroup(array $group, $clear = false) |
19 | { |
20 | $this->getSession()->setGroup($group, $clear); |
21 | } |
22 | |
23 | public function writeData() |
24 | { |
25 | $this->getSession()->writeData(); |
26 | } |
27 | |
28 | public function set($key, $value, $index = null) |
29 | { |
30 | $this->getSession()->set($key, $value, $index); |
31 | } |
32 | |
33 | public function get($key, $index = null, $default = null) |
34 | { |
35 | return $this->getSession()->get($key, $index, $default); |
36 | } |
37 | |
38 | public function getEntity() |
39 | { |
40 | return $this->getSession()->getEntity(); |
41 | } |
42 | |
43 | public function remove($key, $groupIndex = null) |
44 | { |
45 | $this->getSession()->remove($key, $groupIndex); |
46 | } |
47 | |
48 | public function clear() |
49 | { |
50 | $this->getSession()->clear(); |
51 | } |
52 | |
53 | public function restart() |
54 | { |
55 | $this->getSession()->restart(); |
56 | } |
57 | |
58 | public function clearGroup($groupIndex = null) |
59 | { |
60 | $this->getSession()->clearGroup($groupIndex); |
61 | } |
62 | |
63 | public function has($key, $groupIndex = null) |
64 | { |
65 | return $this->getSession()->has($key, $groupIndex); |
66 | } |
67 | |
68 | public function isEmpty() |
69 | { |
70 | return $this->getSession()->isEmpty(); |
71 | } |
72 | |
73 | // TODO: Review the use of `mixed` return type. |
74 | // This method delegates to getSession()->jsonSerialize(), which may return various types. |
75 | // Consider adding stricter return typing if getSession() can be more precisely typed. |
76 | public function jsonSerialize(): mixed |
77 | { |
78 | return $this->getSession()->jsonSerialize(); |
79 | } |
80 | |
81 | private function getSession() |
82 | { |
83 | if (!$this->sessionContainer) { |
84 | $this->sessionContainer = $this->loadSession(); |
85 | } |
86 | return $this->sessionContainer; |
87 | } |
88 | |
89 | private function loadSession() |
90 | { |
91 | $sessionLoader = $this->sessionLoader; |
92 | return $sessionLoader(); |
93 | } |
94 | } |