137 list($headerKey, $headerValue) = preg_split('#=\s*#', $keyValue, 2); |
137 list($headerKey, $headerValue) = preg_split('#=\s*#', $keyValue, 2); |
138 } else { |
138 } else { |
139 $headerKey = $keyValue; |
139 $headerKey = $keyValue; |
140 $headerValue = null; |
140 $headerValue = null; |
141 } |
141 } |
142 |
142 |
143 // First K=V pair is always the cookie name and value |
143 // First K=V pair is always the cookie name and value |
144 if ($header->getName() === NULL) { |
144 if ($header->getName() === NULL) { |
145 $header->setName($headerKey); |
145 $header->setName($headerKey); |
146 $header->setValue($headerValue); |
146 $header->setValue($headerValue); |
147 continue; |
147 continue; |
237 public function getFieldValue() |
237 public function getFieldValue() |
238 { |
238 { |
239 if ($this->getName() == '') { |
239 if ($this->getName() == '') { |
240 throw new Zend_Http_Header_Exception_RuntimeException('A cookie name is required to generate a field value for this cookie'); |
240 throw new Zend_Http_Header_Exception_RuntimeException('A cookie name is required to generate a field value for this cookie'); |
241 } |
241 } |
242 |
242 |
243 $value = $this->getValue(); |
243 $value = $this->getValue(); |
244 if (strpos($value,'"')!==false) { |
244 if (strpos($value,'"')!==false) { |
245 $value = '"'.urlencode(str_replace('"', '', $value)).'"'; |
245 $value = '"'.urlencode(str_replace('"', '', $value)).'"'; |
246 } else { |
246 } else { |
247 $value = urlencode($value); |
247 $value = urlencode($value); |
250 |
250 |
251 $version = $this->getVersion(); |
251 $version = $this->getVersion(); |
252 if ($version!==null) { |
252 if ($version!==null) { |
253 $fieldValue .= '; Version=' . $version; |
253 $fieldValue .= '; Version=' . $version; |
254 } |
254 } |
255 |
255 |
256 $maxAge = $this->getMaxAge(); |
256 $maxAge = $this->getMaxAge(); |
257 if ($maxAge!==null) { |
257 if ($maxAge!==null) { |
258 $fieldValue .= '; Max-Age=' . $maxAge; |
258 $fieldValue .= '; Max-Age=' . $maxAge; |
259 } |
259 } |
260 |
260 |
261 $expires = $this->getExpires(); |
261 $expires = $this->getExpires(); |
262 if ($expires) { |
262 if ($expires) { |
263 $fieldValue .= '; Expires=' . $expires; |
263 $fieldValue .= '; Expires=' . $expires; |
264 } |
264 } |
265 |
265 |
323 return $this->value; |
323 return $this->value; |
324 } |
324 } |
325 |
325 |
326 /** |
326 /** |
327 * Set version |
327 * Set version |
328 * |
328 * |
329 * @param integer $version |
329 * @param integer $version |
330 */ |
330 */ |
331 public function setVersion($version) |
331 public function setVersion($version) |
332 { |
332 { |
333 if (!is_int($version)) { |
333 if (!is_int($version)) { |
334 throw new Zend_Http_Header_Exception_InvalidArgumentException('Invalid Version number specified'); |
334 throw new Zend_Http_Header_Exception_InvalidArgumentException('Invalid Version number specified'); |
335 } |
335 } |
336 $this->version = $version; |
336 $this->version = $version; |
337 } |
337 } |
338 |
338 |
339 /** |
339 /** |
340 * Get version |
340 * Get version |
341 * |
341 * |
342 * @return integer |
342 * @return integer |
343 */ |
343 */ |
344 public function getVersion() |
344 public function getVersion() |
345 { |
345 { |
346 return $this->version; |
346 return $this->version; |
347 } |
347 } |
348 |
348 |
349 /** |
349 /** |
350 * Set Max-Age |
350 * Set Max-Age |
351 * |
351 * |
352 * @param integer $maxAge |
352 * @param integer $maxAge |
353 */ |
353 */ |
354 public function setMaxAge($maxAge) |
354 public function setMaxAge($maxAge) |
355 { |
355 { |
356 if (!is_int($maxAge) || ($maxAge<0)) { |
356 if (!is_int($maxAge) || ($maxAge<0)) { |
357 throw new Zend_Http_Header_Exception_InvalidArgumentException('Invalid Max-Age number specified'); |
357 throw new Zend_Http_Header_Exception_InvalidArgumentException('Invalid Max-Age number specified'); |
358 } |
358 } |
359 $this->maxAge = $maxAge; |
359 $this->maxAge = $maxAge; |
360 } |
360 } |
361 |
361 |
362 /** |
362 /** |
363 * Get Max-Age |
363 * Get Max-Age |
364 * |
364 * |
365 * @return integer |
365 * @return integer |
366 */ |
366 */ |
367 public function getMaxAge() |
367 public function getMaxAge() |
368 { |
368 { |
369 return $this->maxAge; |
369 return $this->maxAge; |
502 public function isValidForRequest($requestDomain, $path, $isSecure = false) |
502 public function isValidForRequest($requestDomain, $path, $isSecure = false) |
503 { |
503 { |
504 if ($this->getDomain() && (strrpos($requestDomain, $this->getDomain()) !== false)) { |
504 if ($this->getDomain() && (strrpos($requestDomain, $this->getDomain()) !== false)) { |
505 return false; |
505 return false; |
506 } |
506 } |
507 |
507 |
508 if ($this->getPath() && (strpos($path, $this->getPath()) !== 0)) { |
508 if ($this->getPath() && (strpos($path, $this->getPath()) !== 0)) { |
509 return false; |
509 return false; |
510 } |
510 } |
511 |
511 |
512 if ($this->secure && $this->isSecure()!==$isSecure) { |
512 if ($this->secure && $this->isSecure()!==$isSecure) { |
513 return false; |
513 return false; |
514 } |
514 } |
515 |
515 |
516 return true; |
516 return true; |
517 |
517 |
518 } |
518 } |
519 |
519 |
520 public function toString() |
520 public function toString() |
521 { |
521 { |
522 return $this->getFieldName() . ': ' . $this->getFieldValue(); |
522 return $this->getFieldName() . ': ' . $this->getFieldValue(); |
523 } |
523 } |
524 |
524 |
525 public function __toString() |
525 public function __toString() |
526 { |
526 { |
527 return $this->toString(); |
527 return $this->toString(); |
528 } |
528 } |
529 |
529 |