Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| Session | |
100.00% |
7 / 7 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| destroy | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| id | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| set | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Dynart\Micro; |
| 4 | |
| 5 | class Session implements SessionInterface { |
| 6 | |
| 7 | /** |
| 8 | * Starts the session (only once) |
| 9 | */ |
| 10 | public function __construct() { |
| 11 | if (session_status() == PHP_SESSION_NONE) { |
| 12 | session_start(); |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | public function destroy(): void { |
| 17 | $_SESSION = []; |
| 18 | session_destroy(); |
| 19 | } |
| 20 | |
| 21 | public function id(): string { |
| 22 | return session_id(); |
| 23 | } |
| 24 | |
| 25 | public function get(string $name, mixed $default = null): mixed { |
| 26 | return array_key_exists($name, $_SESSION) ? $_SESSION[$name] : $default; |
| 27 | } |
| 28 | |
| 29 | public function set(string $name, mixed $value): void { |
| 30 | $_SESSION[$name] = $value; |
| 31 | } |
| 32 | } |