equal
deleted
inserted
replaced
13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Http |
16 * @package Zend_Http |
17 * @subpackage CookieJar |
17 * @subpackage CookieJar |
18 * @version $Id: CookieJar.php 23443 2010-11-24 11:53:13Z shahar $ |
18 * @version $Id: CookieJar.php 24856 2012-06-01 01:10:47Z adamlundrigan $ |
19 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
20 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @license http://framework.zend.com/license/new-bsd New BSD License |
21 */ |
21 */ |
22 |
22 |
23 /** |
23 /** |
24 * @see Zend_Uri |
24 * @see Zend_Uri |
52 * @link http://wp.netscape.com/newsref/std/cookie_spec.html for some specs. |
52 * @link http://wp.netscape.com/newsref/std/cookie_spec.html for some specs. |
53 * |
53 * |
54 * @category Zend |
54 * @category Zend |
55 * @package Zend_Http |
55 * @package Zend_Http |
56 * @subpackage CookieJar |
56 * @subpackage CookieJar |
57 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
57 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
58 * @license http://framework.zend.com/license/new-bsd New BSD License |
58 * @license http://framework.zend.com/license/new-bsd New BSD License |
59 */ |
59 */ |
60 class Zend_Http_CookieJar implements Countable, IteratorAggregate |
60 class Zend_Http_CookieJar implements Countable, IteratorAggregate |
61 { |
61 { |
62 /** |
62 /** |
74 /** |
74 /** |
75 * Return all cookies as one long string (suitable for sending in an HTTP request) |
75 * Return all cookies as one long string (suitable for sending in an HTTP request) |
76 * |
76 * |
77 */ |
77 */ |
78 const COOKIE_STRING_CONCAT = 2; |
78 const COOKIE_STRING_CONCAT = 2; |
|
79 |
|
80 /** |
|
81 * Return all cookies as one long string (strict mode) |
|
82 * - Single space after the semi-colon separating each cookie |
|
83 * - Remove trailing semi-colon, if any |
|
84 */ |
|
85 const COOKIE_STRING_CONCAT_STRICT = 3; |
79 |
86 |
80 /** |
87 /** |
81 * Array storing cookies |
88 * Array storing cookies |
82 * |
89 * |
83 * Cookies are stored according to domain and path: |
90 * Cookies are stored according to domain and path: |
171 * @return array|string |
178 * @return array|string |
172 */ |
179 */ |
173 public function getAllCookies($ret_as = self::COOKIE_OBJECT) |
180 public function getAllCookies($ret_as = self::COOKIE_OBJECT) |
174 { |
181 { |
175 $cookies = $this->_flattenCookiesArray($this->cookies, $ret_as); |
182 $cookies = $this->_flattenCookiesArray($this->cookies, $ret_as); |
|
183 if($ret_as == self::COOKIE_STRING_CONCAT_STRICT) { |
|
184 $cookies = rtrim(trim($cookies), ';'); |
|
185 } |
176 return $cookies; |
186 return $cookies; |
177 } |
187 } |
178 |
188 |
179 /** |
189 /** |
180 * Return an array of all cookies matching a specific request according to the request URI, |
190 * Return an array of all cookies matching a specific request according to the request URI, |
207 if ($cookie->match($uri, $matchSessionCookies, $now)) |
217 if ($cookie->match($uri, $matchSessionCookies, $now)) |
208 $ret[] = $cookie; |
218 $ret[] = $cookie; |
209 |
219 |
210 // Now, use self::_flattenCookiesArray again - only to convert to the return format ;) |
220 // Now, use self::_flattenCookiesArray again - only to convert to the return format ;) |
211 $ret = $this->_flattenCookiesArray($ret, $ret_as); |
221 $ret = $this->_flattenCookiesArray($ret, $ret_as); |
|
222 if($ret_as == self::COOKIE_STRING_CONCAT_STRICT) { |
|
223 $ret = rtrim(trim($ret), ';'); |
|
224 } |
212 |
225 |
213 return $ret; |
226 return $ret; |
214 } |
227 } |
215 |
228 |
216 /** |
229 /** |
243 switch ($ret_as) { |
256 switch ($ret_as) { |
244 case self::COOKIE_OBJECT: |
257 case self::COOKIE_OBJECT: |
245 return $cookie; |
258 return $cookie; |
246 break; |
259 break; |
247 |
260 |
|
261 case self::COOKIE_STRING_CONCAT_STRICT: |
|
262 return rtrim(trim($cookie->__toString()), ';'); |
|
263 break; |
|
264 |
248 case self::COOKIE_STRING_ARRAY: |
265 case self::COOKIE_STRING_ARRAY: |
249 case self::COOKIE_STRING_CONCAT: |
266 case self::COOKIE_STRING_CONCAT: |
250 return $cookie->__toString(); |
267 return $cookie->__toString(); |
251 break; |
268 break; |
252 |
269 |
268 * @param int $ret_as What value to return |
285 * @param int $ret_as What value to return |
269 * @return array|string |
286 * @return array|string |
270 */ |
287 */ |
271 protected function _flattenCookiesArray($ptr, $ret_as = self::COOKIE_OBJECT) { |
288 protected function _flattenCookiesArray($ptr, $ret_as = self::COOKIE_OBJECT) { |
272 if (is_array($ptr)) { |
289 if (is_array($ptr)) { |
273 $ret = ($ret_as == self::COOKIE_STRING_CONCAT ? '' : array()); |
290 $ret = ($ret_as == self::COOKIE_STRING_CONCAT || $ret_as == self::COOKIE_STRING_CONCAT_STRICT) ? '' : array(); |
274 foreach ($ptr as $item) { |
291 foreach ($ptr as $item) { |
275 if ($ret_as == self::COOKIE_STRING_CONCAT) { |
292 if ($ret_as == self::COOKIE_STRING_CONCAT_STRICT) { |
|
293 $postfix_combine = (!is_array($item) ? ' ' : ''); |
|
294 $ret .= $this->_flattenCookiesArray($item, $ret_as) . $postfix_combine; |
|
295 } elseif ($ret_as == self::COOKIE_STRING_CONCAT) { |
276 $ret .= $this->_flattenCookiesArray($item, $ret_as); |
296 $ret .= $this->_flattenCookiesArray($item, $ret_as); |
277 } else { |
297 } else { |
278 $ret = array_merge($ret, $this->_flattenCookiesArray($item, $ret_as)); |
298 $ret = array_merge($ret, $this->_flattenCookiesArray($item, $ret_as)); |
279 } |
299 } |
280 } |
300 } |
282 } elseif ($ptr instanceof Zend_Http_Cookie) { |
302 } elseif ($ptr instanceof Zend_Http_Cookie) { |
283 switch ($ret_as) { |
303 switch ($ret_as) { |
284 case self::COOKIE_STRING_ARRAY: |
304 case self::COOKIE_STRING_ARRAY: |
285 return array($ptr->__toString()); |
305 return array($ptr->__toString()); |
286 break; |
306 break; |
|
307 |
|
308 case self::COOKIE_STRING_CONCAT_STRICT: |
|
309 // break intentionally omitted |
287 |
310 |
288 case self::COOKIE_STRING_CONCAT: |
311 case self::COOKIE_STRING_CONCAT: |
289 return $ptr->__toString(); |
312 return $ptr->__toString(); |
290 break; |
313 break; |
291 |
314 |