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 | #[\Override] |
| 19 | public function setGroup(array $group, $clear = false) |
| 20 | { |
| 21 | $this->getSession()->setGroup($group, $clear); |
| 22 | } |
| 23 | |
| 24 | public function writeData() |
| 25 | { |
| 26 | $this->getSession()->writeData(); |
| 27 | } |
| 28 | |
| 29 | #[\Override] |
| 30 | public function set($key, $value, $groupIndex = null) |
| 31 | { |
| 32 | $this->getSession()->set($key, $value, $groupIndex); |
| 33 | } |
| 34 | |
| 35 | #[\Override] |
| 36 | public function get($key, $groupIndex = null, $default = null) |
| 37 | { |
| 38 | return $this->getSession()->get($key, $groupIndex, $default); |
| 39 | } |
| 40 | |
| 41 | #[\Override] |
| 42 | public function getEntity() |
| 43 | { |
| 44 | return $this->getSession()->getEntity(); |
| 45 | } |
| 46 | |
| 47 | #[\Override] |
| 48 | public function remove($key, $groupIndex = null) |
| 49 | { |
| 50 | $this->getSession()->remove($key, $groupIndex); |
| 51 | } |
| 52 | |
| 53 | #[\Override] |
| 54 | public function clear() |
| 55 | { |
| 56 | $this->getSession()->clear(); |
| 57 | } |
| 58 | |
| 59 | public function restart() |
| 60 | { |
| 61 | $this->getSession()->restart(); |
| 62 | } |
| 63 | |
| 64 | #[\Override] |
| 65 | public function clearGroup($groupIndex = null) |
| 66 | { |
| 67 | $this->getSession()->clearGroup($groupIndex); |
| 68 | } |
| 69 | |
| 70 | #[\Override] |
| 71 | public function has($key, $groupIndex = null) |
| 72 | { |
| 73 | return $this->getSession()->has($key, $groupIndex); |
| 74 | } |
| 75 | |
| 76 | #[\Override] |
| 77 | public function isEmpty() |
| 78 | { |
| 79 | return $this->getSession()->isEmpty(); |
| 80 | } |
| 81 | |
| 82 | // TODO: Review the use of `mixed` return type. |
| 83 | // This method delegates to getSession()->jsonSerialize(), which may return various types. |
| 84 | // Consider adding stricter return typing if getSession() can be more precisely typed. |
| 85 | #[\Override] |
| 86 | public function jsonSerialize(): mixed |
| 87 | { |
| 88 | return $this->getSession()->jsonSerialize(); |
| 89 | } |
| 90 | |
| 91 | private function getSession() |
| 92 | { |
| 93 | if (!$this->sessionContainer) { |
| 94 | $this->sessionContainer = $this->loadSession(); |
| 95 | } |
| 96 | return $this->sessionContainer; |
| 97 | } |
| 98 | |
| 99 | private function loadSession() |
| 100 | { |
| 101 | $sessionLoader = $this->sessionLoader; |
| 102 | return $sessionLoader(); |
| 103 | } |
| 104 | } |