1 | <?php namespace Comodojo\Cookies; |
||
23 | abstract class AbstractCookie implements CookieInterface { |
||
24 | |||
25 | /** |
||
26 | * The cookie name |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $name = null; |
||
31 | |||
32 | /** |
||
33 | * Cookie value (native string or serialized one) |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $value = null; |
||
38 | |||
39 | /** |
||
40 | * Expiration time |
||
41 | * |
||
42 | * @var integer |
||
43 | */ |
||
44 | protected $expire = null; |
||
45 | |||
46 | /** |
||
47 | * Path of cookie |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $path = null; |
||
52 | |||
53 | /** |
||
54 | * Domain of cookie |
||
55 | * |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $domain = null; |
||
59 | |||
60 | /** |
||
61 | * Secure flag |
||
62 | * |
||
63 | * @var bool |
||
64 | */ |
||
65 | protected $secure = false; |
||
66 | |||
67 | /** |
||
68 | * Httponly flag |
||
69 | * |
||
70 | * @var bool |
||
71 | */ |
||
72 | protected $httponly = false; |
||
73 | |||
74 | /* |
||
75 | * Max cookie size |
||
76 | * |
||
77 | * Should be 4096 max |
||
78 | * |
||
79 | * @var int |
||
80 | */ |
||
81 | protected $max_cookie_size = 4000; |
||
82 | |||
83 | /** |
||
84 | * Default cookie's constructor |
||
85 | * |
||
86 | * @param string $name |
||
87 | * @param int $max_cookie_size |
||
88 | * |
||
89 | * @throws CookieException |
||
90 | */ |
||
91 | 99 | public function __construct($name, $max_cookie_size = null) { |
|
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | 99 | public function setName($name) { |
|
127 | |||
128 | /** |
||
129 | * {@inheritdoc} |
||
130 | */ |
||
131 | 9 | public function getName() { |
|
136 | |||
137 | /** |
||
138 | * {@inheritdoc} |
||
139 | */ |
||
140 | abstract function setValue($value, $serialize); |
||
141 | |||
142 | /** |
||
143 | * {@inheritdoc} |
||
144 | */ |
||
145 | abstract function getValue($unserialize); |
||
146 | |||
147 | /** |
||
148 | * {@inheritdoc} |
||
149 | */ |
||
150 | 3 | public function setExpire($timestamp) { |
|
159 | |||
160 | /** |
||
161 | * {@inheritdoc} |
||
162 | */ |
||
163 | 3 | public function setPath($location) { |
|
172 | |||
173 | /** |
||
174 | * {@inheritdoc} |
||
175 | */ |
||
176 | 3 | public function setDomain($domain) { |
|
185 | |||
186 | /** |
||
187 | * {@inheritdoc} |
||
188 | */ |
||
189 | 3 | public function setSecure($mode = true) { |
|
196 | |||
197 | /** |
||
198 | * {@inheritdoc} |
||
199 | */ |
||
200 | 3 | public function setHttponly($mode = true) { |
|
207 | |||
208 | /** |
||
209 | * {@inheritdoc} |
||
210 | */ |
||
211 | public function save() { |
||
226 | |||
227 | /** |
||
228 | * {@inheritdoc} |
||
229 | */ |
||
230 | 12 | public function load() { |
|
239 | |||
240 | /** |
||
241 | * {@inheritdoc} |
||
242 | */ |
||
243 | 6 | public function delete() { |
|
260 | |||
261 | /** |
||
262 | * {@inheritdoc} |
||
263 | */ |
||
264 | 21 | public function exists() { |
|
269 | |||
270 | /** |
||
271 | * Static method to delete a cookie quickly |
||
272 | * |
||
273 | * @param string $name The cookie name |
||
274 | * |
||
275 | * @return boolean |
||
276 | * |
||
277 | * @throws \Comodojo\Exception\CookieException |
||
278 | */ |
||
279 | 3 | public static function erase($name) { |
|
296 | |||
297 | /** |
||
298 | * Set content of $cookie from array $properties |
||
299 | * |
||
300 | * @param \Comodojo\Cookies\CookieInterface\CookieInterface $cookie |
||
301 | * |
||
302 | * @param array $properties Array of properties cookie should have |
||
303 | * |
||
304 | * @param boolean $serialize |
||
305 | * |
||
306 | * @return \Comodojo\Cookies\CookieBase |
||
307 | */ |
||
308 | 9 | protected static function cookieProperties(CookieInterface $cookie, $properties, $serialize) { |
|
357 | |||
358 | /** |
||
359 | * Check if domain is valid |
||
360 | * |
||
361 | * Main code from: http://stackoverflow.com/questions/1755144/how-to-validate-domain-name-in-php |
||
362 | * |
||
363 | * @param string $domain_name The domain name to check |
||
364 | * |
||
365 | * @return bool |
||
366 | */ |
||
367 | 3 | protected static function checkDomain($domain_name) { |
|
376 | |||
377 | } |
||
378 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.