-
Notifications
You must be signed in to change notification settings - Fork 17
/
Cookie.php
185 lines (169 loc) · 3.59 KB
/
Cookie.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/**
* This file is part of the Cygnite package.
*
* (c) Sanjoy Dey <dey.sanjoy0@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Cygnite\Common\Input;
use Cygnite\Common\Input\CookieManager\CookieInterface;
use Cygnite\Common\Input\CookieManager\CookieManager;
/**
* Class Cookie.
*/
class Cookie implements CookieInterface
{
public static $cookie;
/**
* Create Cookie manager and store or access cookie
* information.
*/
public function __construct()
{
static::$cookie = CookieManager::create();
}
/**
* Create Cookie Instance and return to user.
*
* @return static
*/
public static function create()
{
return new static();
}
/**
* Set cookie name.
*
* @param string $name cookie name
*
* @throws \InvalidCookieException
*
* @return mixed obj or bool false
*/
public static function name($name)
{
return static::$cookie->name($name);
}
/**
* Set cookie value.
*
* @param string $value cookie value
*
* @throws \InvalidCookieException
*
* @internal param bool $encrypt
*
* @return bool whether the string was a string
*/
public function value($value = null)
{
return static::$cookie->name($value);
}
/**
* Set cookie expire time.
*
* @param int $expire
*
* @throws \InvalidCookieException
*
* @internal param string $time +1 day, etc.
*
* @return bool whether the string was a string
*/
public function expire($expire = 0)
{
return static::$cookie->name($expire);
}
/**
* Set cookie path.
*
* @param string $path The cookie path
*
* @return $this
*/
public function path($path = '/')
{
return static::$cookie->path($path);
}
/**
* Set the cookie domain.
*
* @param string $domain The cookie path
*
* @return $this
*/
public function domain($domain = null)
{
return static::$cookie->domain($domain);
}
/**
* Set the cookie status to be secure or not.
*
* @param bool $bool true/false if secure
*
* @return $this
*/
public function secure($bool = false)
{
return static::$cookie->secure($bool);
}
/**
* Set the cookie type http only, or not.
*
* @param bool $bool true/false if http only
*
* @return $this
*/
public function httpOnly($bool = false)
{
return static::$cookie->httpOnly($bool);
}
/**
* Get a cookie's value.
*
* @param string $name The cookie name
*
* @return mixed string /bool - The value of the cookie name
*/
public function get($name = null)
{
return static::$cookie->get($name);
}
/**
* Set the cookie.
*
* @throws \Exceptions Cookies already set
*
* @return bool
*/
public function store()
{
return static::$cookie->save();
}
/**
* Check cookie existance.
*
* @param $cookie
*
* @return bool|mixed
*/
public function has($cookie)
{
return static::$cookie->has($cookie);
}
/**
* Destroy the cookie.
*
* @param null $name
*
* @internal param string $cookieName to kill
*
* @return bool true/false
*/
public function destroy($name = null)
{
return static::$cookie->destroy($name);
}
}