Total Complexity | 6 |
Total Lines | 76 |
Duplicated Lines | 0 % |
Coverage | 62.5% |
Changes | 0 |
1 | <?php |
||
14 | class CakeSessionStorage implements StorageInterface |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $key = 'Auth'; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $attribute = 'session'; |
||
26 | |||
27 | /** |
||
28 | * Set request attribute name for a session object. |
||
29 | * |
||
30 | * @param string $attribute Request attribute name. |
||
31 | * @return $this |
||
32 | */ |
||
33 | public function setAttribute(string $attribute): self |
||
34 | { |
||
35 | $this->attribute = $attribute; |
||
36 | |||
37 | return $this; |
||
38 | } |
||
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 | 1 | public function clear(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
|
57 | { |
||
58 | 1 | $this->getSession($request)->delete($this->key); |
|
59 | |||
60 | 1 | return $response; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * {@inheritDoc} |
||
65 | */ |
||
66 | 1 | public function read(ServerRequestInterface $request) |
|
67 | { |
||
68 | 1 | return $this->getSession($request)->read($this->key); |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * {@inheritDoc} |
||
73 | */ |
||
74 | 1 | public function write(ServerRequestInterface $request, ResponseInterface $response, $data): ResponseInterface |
|
75 | { |
||
76 | 1 | $this->getSession($request)->write($this->key, $data); |
|
77 | |||
78 | 1 | return $response; |
|
79 | } |
||
80 | |||
81 | /** |
||
82 | * Returns session object. |
||
83 | * |
||
84 | * @param ServerRequestInterface $request Request. |
||
85 | * @return Session |
||
86 | */ |
||
87 | 3 | protected function getSession(ServerRequestInterface $request): Session |
|
90 | } |
||
91 | } |
||
92 |