1+ <?php
2+ /**
3+ * Slim - a micro PHP 5 framework
4+ *
5+ * @author Josh Lockhart <info@joshlockhart.com>
6+ * @copyright 2011 Josh Lockhart
7+ * @link http://www.slimframework.com
8+ * @license http://www.slimframework.com/license
9+ * @version 1.5.0
10+ *
11+ * MIT LICENSE
12+ *
13+ * Permission is hereby granted, free of charge, to any person obtaining
14+ * a copy of this software and associated documentation files (the
15+ * "Software"), to deal in the Software without restriction, including
16+ * without limitation the rights to use, copy, modify, merge, publish,
17+ * distribute, sublicense, and/or sell copies of the Software, and to
18+ * permit persons to whom the Software is furnished to do so, subject to
19+ * the following conditions:
20+ *
21+ * The above copyright notice and this permission notice shall be
22+ * included in all copies or substantial portions of the Software.
23+ *
24+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31+ */
32+
33+ /**
34+ * Cookie
35+ *
36+ * Object-oriented representation of a Cookie to be sent in an HTTP response
37+ *
38+ * @package Slim
39+ * @author Josh Lockhart <info@joshlockhart.com>
40+ * @since Version 1.0
41+ */
42+ class Slim_Http_Cookie {
43+
44+ /**
45+ * @var string
46+ */
47+ protected $ name ;
48+
49+ /**
50+ * @var string
51+ */
52+ protected $ value ;
53+
54+ /**
55+ * @var int UNIX timestamp
56+ */
57+ protected $ expires ;
58+
59+ /**
60+ * @var string
61+ */
62+ protected $ path ;
63+
64+ /**
65+ * @var string
66+ */
67+ protected $ domain ;
68+
69+ /**
70+ * @var bool
71+ */
72+ protected $ secure ;
73+
74+ /**
75+ * @var bool
76+ */
77+ protected $ httponly ;
78+
79+ /**
80+ * Constructor
81+ * @param string $name The cookie name
82+ * @param string $value The cookie value
83+ * @param mixed $time The duration of the cookie;
84+ * If integer, should be a UNIX timestamp;
85+ * If string, converted to UNIX timestamp with `strtotime`;
86+ * @param string $path The path on the server in which the cookie will be available on
87+ * @param string $domain The domain that the cookie is available to
88+ * @param bool $secure Indicates that the cookie should only be transmitted over a secure
89+ * HTTPS connection from the client
90+ * @param bool $httponly When TRUE the cookie will be made accessible only through the HTTP protocol
91+ * @return void
92+ */
93+ public function __construct ( $ name , $ value = null , $ expires = 0 , $ path = null , $ domain = null , $ secure = false , $ httponly = false ) {
94+ $ this ->setName ($ name );
95+ $ this ->setValue ($ value );
96+ $ this ->setExpires ($ expires );
97+ $ this ->setPath ($ path );
98+ $ this ->setDomain ($ domain );
99+ $ this ->setSecure ($ secure );
100+ $ this ->setHttpOnly ($ httponly );
101+ }
102+
103+ /**
104+ * Get cookie name
105+ * @return string
106+ */
107+ public function getName () {
108+ return $ this ->name ;
109+ }
110+
111+ /**
112+ * Set cookie name
113+ * @param string $name
114+ * @return void
115+ */
116+ public function setName ( $ name ) {
117+ $ this ->name = (string )$ name ;
118+ }
119+
120+ /**
121+ * Get cookie value
122+ * @return string
123+ */
124+ public function getValue () {
125+ return $ this ->value ;
126+ }
127+
128+ /**
129+ * Set cookie value
130+ * @param string $value
131+ * @return void
132+ */
133+ public function setValue ( $ value ) {
134+ $ this ->value = (string )$ value ;
135+ }
136+
137+ /**
138+ * Get cookie expiration time
139+ * @return int UNIX timestamp
140+ */
141+ public function getExpires () {
142+ return $ this ->expires ;
143+ }
144+
145+ /**
146+ * Set cookie expiration time
147+ * @param string|int Cookie expiration time
148+ * @return void
149+ */
150+ public function setExpires ( $ time ) {
151+ $ this ->expires = is_string ($ time ) ? strtotime ($ time ) : (int )$ time ;
152+ }
153+
154+ /**
155+ * Get cookie path
156+ * @return string
157+ */
158+ public function getPath () {
159+ return $ this ->path ;
160+ }
161+
162+ /**
163+ * Set cookie path
164+ * @param string $path
165+ * @return void
166+ */
167+ public function setPath ( $ path ) {
168+ $ this ->path = (string )$ path ;
169+ }
170+
171+ /**
172+ * Get cookie domain
173+ * @return string
174+ */
175+ public function getDomain () {
176+ return $ this ->domain ;
177+ }
178+
179+ /**
180+ * Set cookie domain
181+ * @param string $domain
182+ * @return void
183+ */
184+ public function setDomain ( $ domain ) {
185+ $ this ->domain = (string )$ domain ;
186+ }
187+
188+ /**
189+ * Is cookie sent only if SSL/HTTPS is used?
190+ * @return bool
191+ */
192+ public function getSecure () {
193+ return $ this ->secure ;
194+ }
195+
196+ /**
197+ * Set whether cookie is sent only if SSL/HTTPS is used
198+ * @param bool $secure
199+ * @return void
200+ */
201+ public function setSecure ( $ secure ) {
202+ $ this ->secure = (bool )$ secure ;
203+ }
204+
205+ /**
206+ * Is cookie sent with HTTP protocol only?
207+ * @return bool
208+ */
209+ public function getHttpOnly () {
210+ return $ this ->httponly ;
211+ }
212+
213+ /**
214+ * Set whether cookie is sent with HTTP protocol only
215+ * @param bool $httponly
216+ * @return void
217+ */
218+ public function setHttpOnly ( $ httponly ) {
219+ $ this ->httponly = (bool )$ httponly ;
220+ }
221+
222+ }
0 commit comments