1 | <?php |
||
20 | class CookieManager { |
||
21 | |||
22 | const COOKIE_NAME = 'name'; |
||
23 | const COOKIE_TIME = 'time'; |
||
24 | private $info = null; |
||
25 | |||
26 | public function __construct($info) { |
||
29 | |||
30 | /** |
||
31 | * @param $callMode |
||
32 | * @return mixed|string |
||
33 | * @throws CookieExpiredException |
||
34 | * @throws CookieInvalidException |
||
35 | */ |
||
36 | public function tryParseCookie($callMode) { |
||
37 | $parsedCookie = Cookie::get($this->info[CookieManager::COOKIE_NAME]); |
||
38 | |||
39 | if (isset($parsedCookie)) { |
||
40 | $parsedCookie = json_decode($parsedCookie, true); |
||
41 | $this->validateCookie($parsedCookie); |
||
42 | } else { |
||
43 | if ($callMode !== ProxyAux::MODE_LOGIN) { |
||
44 | throw new CookieExpiredException(); |
||
45 | } |
||
46 | } |
||
47 | |||
48 | return $parsedCookie; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @param array $content |
||
53 | * @return mixed |
||
54 | */ |
||
55 | public function createCookie(Array $content) { |
||
56 | if (!isset($this->info[CookieManager::COOKIE_TIME]) || $this->info[CookieManager::COOKIE_TIME] == null) { |
||
57 | $cookie = Cookie::forever($this->info[CookieManager::COOKIE_NAME], json_encode($content)); |
||
58 | } else { |
||
59 | $cookie = Cookie::make($this->info[CookieManager::COOKIE_NAME], json_encode($content), $this->info[CookieManager::COOKIE_TIME]); |
||
60 | } |
||
61 | |||
62 | return $cookie; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return mixed |
||
67 | */ |
||
68 | public function destroyCookie() { |
||
71 | |||
72 | /** |
||
73 | * @param $parsedCookie |
||
74 | * @return bool |
||
75 | * @throws CookieInvalidException |
||
76 | */ |
||
77 | public function validateCookie($parsedCookie) { |
||
96 | |||
97 | } |
||
98 |