Total Complexity | 6 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Coverage | 81.25% |
Changes | 0 |
1 | <?php |
||
22 | class NativePhpSessionStorage implements StorageInterface |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $key = 'Auth'; |
||
29 | |||
30 | /** |
||
31 | * Constructor |
||
32 | * |
||
33 | * @var string $key Key |
||
34 | */ |
||
35 | 6 | public function __construct(string $sessionKey) |
|
36 | { |
||
37 | 6 | $this->key = $sessionKey; |
|
38 | 6 | } |
|
39 | |||
40 | /** |
||
41 | * Set session key for stored identity. |
||
42 | * |
||
43 | * @param string $key Session key. |
||
44 | * @return $this |
||
45 | */ |
||
46 | public function setKey(string $key): self |
||
47 | { |
||
48 | $this->key = $key; |
||
49 | |||
50 | return $this; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * {@inheritDoc} |
||
55 | */ |
||
56 | 3 | public function clear(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
|
57 | { |
||
58 | 3 | unset($_SESSION[$this->key]); |
|
59 | |||
60 | 3 | return $response; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * {@inheritDoc} |
||
65 | */ |
||
66 | 6 | public function read(ServerRequestInterface $request) |
|
67 | { |
||
68 | 6 | if (!isset($_SESSION[$this->key])) { |
|
69 | 6 | return null; |
|
70 | } |
||
71 | |||
72 | 3 | return $_SESSION[$this->key]; |
|
73 | } |
||
74 | |||
75 | /** |
||
76 | * {@inheritDoc} |
||
77 | */ |
||
78 | 3 | public function write(ServerRequestInterface $request, ResponseInterface $response, $data): ResponseInterface |
|
83 | } |
||
84 | } |
||
85 |