1 | <?php |
||
7 | class VanillaCookie implements Cookie |
||
8 | { |
||
9 | /** |
||
10 | * Encrypter |
||
11 | * |
||
12 | * @var \CodeZero\Encrypter\Encrypter |
||
13 | */ |
||
14 | protected $encrypter; |
||
15 | |||
16 | /** |
||
17 | * Create a new instance of VanillaCookie |
||
18 | * |
||
19 | * @param \CodeZero\Encrypter\Encrypter $encrypter |
||
20 | */ |
||
21 | 10 | public function __construct(Encrypter $encrypter = null) |
|
25 | |||
26 | /** |
||
27 | * Get the value of a cookie |
||
28 | * |
||
29 | * @param string $cookieName |
||
30 | * |
||
31 | * @return null|string |
||
32 | * @throws \CodeZero\Encrypter\DecryptException |
||
33 | */ |
||
34 | 5 | public function get($cookieName) |
|
42 | |||
43 | /** |
||
44 | * Store a cookie |
||
45 | * |
||
46 | * @param string $cookieName |
||
47 | * @param string $cookieValue |
||
48 | * @param int $minutes |
||
49 | * @param string $path |
||
50 | * @param string $domain |
||
51 | * @param bool $secure |
||
52 | * @param bool $httpOnly |
||
53 | * |
||
54 | * @return bool |
||
55 | */ |
||
56 | 6 | public function store($cookieName, $cookieValue, $minutes = 60, $path = "/", $domain = null, $secure = true, $httpOnly = true) |
|
68 | |||
69 | /** |
||
70 | * Store a cookie for a long, long time |
||
71 | * |
||
72 | * @param string $cookieName |
||
73 | * @param string $cookieValue |
||
74 | * @param string $path |
||
75 | * @param string $domain |
||
76 | * @param bool $secure |
||
77 | * @param bool $httpOnly |
||
78 | * |
||
79 | * @return bool |
||
80 | */ |
||
81 | 1 | public function forever($cookieName, $cookieValue, $path = '/', $domain = null, $secure = null, $httpOnly = true) |
|
85 | |||
86 | /** |
||
87 | * Delete a cookie |
||
88 | * |
||
89 | * @param string $cookieName |
||
90 | * @param string $path |
||
91 | * @param string $domain |
||
92 | * |
||
93 | * @return null|bool |
||
94 | */ |
||
95 | 2 | public function delete($cookieName, $path = '/', $domain = null) |
|
105 | |||
106 | /** |
||
107 | * Check if a cookie exists |
||
108 | * |
||
109 | * @param string $cookieName |
||
110 | * |
||
111 | * @return bool |
||
112 | */ |
||
113 | 6 | public function exists($cookieName) |
|
117 | |||
118 | /** |
||
119 | * Calculate the expiration time |
||
120 | * |
||
121 | * @param int $minutes |
||
122 | * |
||
123 | * @return int |
||
124 | */ |
||
125 | 6 | protected function calculateExpirationTime($minutes) |
|
129 | |||
130 | /** |
||
131 | * Encrypt a cookie |
||
132 | * |
||
133 | * @param string $cookieValue |
||
134 | * |
||
135 | * @return string |
||
136 | */ |
||
137 | 6 | protected function encrypt($cookieValue) |
|
145 | |||
146 | /** |
||
147 | * Decrypt a cookie |
||
148 | * |
||
149 | * @param string $cookieValue |
||
150 | * |
||
151 | * @return string |
||
152 | * @throws \CodeZero\Encrypter\DecryptException |
||
153 | */ |
||
154 | 3 | protected function decrypt($cookieValue) |
|
162 | } |
||
163 |