Lines
100.00%
10 / 10
Methods
100.00%
5 / 5
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 3 | ||
| get | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| set | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| has | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| remove | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| 25 | class SessionWrapper | |
| 26 | { | |
| 27 | private Session $session; | |
| 28 | ||
| 29 | public function __construct(?Session $session = null) | |
| 30 | { | |
| 31 | if ($session instanceof Session) { | |
| 32 | $this->session = $session; | |
| 33 | return; | |
| 34 | } | |
| 35 | ||
| 36 | // If no session is provided, create one with PhpBridgeSessionStorage | |
| 37 | // This connects to the existing PHP session | |
| 38 | $this->session = new Session(new PhpBridgeSessionStorage()); | |
| 39 | if (!$this->session->isStarted()) { | |
| 40 | $this->session->start(); | |
| 41 | } | |
| 42 | } | |
| 43 | ||
| 44 | /** | |
| 45 | * Get a value from the session | |
| 46 | */ | |
| 47 | public function get(string $key, mixed $default = null): mixed | |
| 48 | { | |
| 49 | return $this->session->get($key, $default); | |
| 50 | } | |
| 51 | ||
| 52 | /** | |
| 53 | * Set a value in the session | |
| 54 | */ | |
| 55 | public function set(string $key, mixed $value): void | |
| 56 | { | |
| 57 | $this->session->set($key, $value); | |
| 58 | } | |
| 59 | ||
| 60 | /** | |
| 61 | * Check if a key exists in the session | |
| 62 | */ | |
| 63 | public function has(string $key): bool | |
| 64 | { | |
| 65 | return $this->session->has($key); | |
| 66 | } | |
| 67 | ||
| 68 | /** | |
| 69 | * Remove a key from the session | |
| 70 | */ | |
| 71 | public function remove(string $key): mixed | |
| 72 | { | |
| 73 | return $this->session->remove($key); | |
| 74 | } | |
| 75 | } |