1 | <?php |
||
19 | class Cookie |
||
20 | { |
||
21 | |||
22 | const ISSUER = 'zortje/mvc'; |
||
23 | |||
24 | /** |
||
25 | * @var Configuration |
||
26 | */ |
||
27 | protected $configuration; |
||
28 | |||
29 | /** |
||
30 | * @var string[] Internal cookie values |
||
31 | */ |
||
32 | protected $values = []; |
||
33 | |||
34 | /** |
||
35 | * Cookie constructor. |
||
36 | * |
||
37 | * @param Configuration $configuration Configuration |
||
38 | * @param string $token JWT string |
||
39 | */ |
||
40 | public function __construct(Configuration $configuration, string $token = '') |
||
41 | { |
||
42 | $this->configuration = $configuration; |
||
43 | $this->values = $this->parseAndValidateToken($token); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Set value in cookie |
||
48 | * |
||
49 | * @param string $key Cookie key |
||
50 | * @param string $value Cookie value |
||
51 | */ |
||
52 | public function set(string $key, string $value) |
||
53 | { |
||
54 | $this->values[$key] = $value; |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Get value from cookie |
||
59 | * |
||
60 | * @param string $key Cookie key |
||
61 | * |
||
62 | * @return string Cookie value |
||
63 | * |
||
64 | * @throws CookieUndefinedIndexException |
||
65 | */ |
||
66 | public function get(string $key): string |
||
67 | { |
||
68 | if (isset($this->values[$key]) === false) { |
||
69 | throw new CookieUndefinedIndexException([$key]); |
||
70 | } |
||
71 | |||
72 | return $this->values[$key]; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @return string JWT string |
||
77 | */ |
||
78 | public function getTokenString(): string |
||
100 | |||
101 | protected function parseAndValidateToken(string $token) |
||
132 | } |
||
133 |