-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFSiteCookie.php
executable file
·59 lines (50 loc) · 1.51 KB
/
FSiteCookie.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* User indepent cookie for storing various sistem wide states
*/
class FSiteCookie extends CApplicationComponent
{
public $timeOut = 0;
public $httpOnly = true;
public $cookieName = 'ux';
public function init()
{
parent::init();
if (isset(Yii::app()->request->cookies[$this->cookieName])) {
return;
}
$exp = time() + $this->timeOut;
$this->create(array('exp' => $exp), $exp);
}
public function get($key)
{
if (isset(Yii::app()->request->cookies[$this->cookieName]->value[$key])) {
return Yii::app()->request->cookies[$this->cookieName]->value[$key];
}
return false;
}
public function set($key, $val, $refreshExpiration = false)
{
$cookie = Yii::app()->request->cookies[$this->cookieName];
$exp = ($refreshExpiration) ? time() + $this->timeOut : $cookie->value['exp'];
$cookie->value[$key] = $val;
$cookie->value['exp'] = $exp;
$this->create($cookie->value, $exp);
}
public function create($values, $exp)
{
Yii::app()->request->cookies[$this->cookieName] = new CHttpCookie(
$this->cookieName,
$values,
array(
'expire' => $exp,
'httpOnly' => $this->httpOnly,
'domain' => Yii::app()->session->cookieParams['domain'],
)
);
}
public function delete()
{
unset(Yii::app()->request->cookies[$this->cookieName]);
}
}