Пример #1
0
 public function testRemoveExpiredOnUnserialize()
 {
     $dt = new DateTime();
     $dt->setTimezone(new DateTimeZone('UTC'));
     $dt->modify('+2 seconds');
     $this->jar->store(array('name' => 'foo', 'value' => 'bar', 'domain' => '.example.com', 'path' => '/', 'expires' => $dt->format(DateTime::COOKIE)));
     $serialized = serialize($this->jar);
     sleep(2);
     $newJar = unserialize($serialized);
     $this->assertEquals(array(), $newJar->getAll());
 }
Пример #2
0
 /**
  * Adds a cookie to the request
  *
  * If the request does not have a CookieJar object set, this method simply
  * appends a cookie to "Cookie:" header.
  *
  * If a CookieJar object is available, the cookie is stored in that object.
  * Data from request URL will be used for setting its 'domain' and 'path'
  * parameters, 'expires' and 'secure' will be set to null and false,
  * respectively. If you need further control, use CookieJar's methods.
  *
  * @param string $name  cookie name
  * @param string $value cookie value
  *
  * @return   HTTP_Request2
  * @throws   HTTP_Request2_LogicException
  * @see      setCookieJar()
  */
 public function addCookie($name, $value)
 {
     if (!empty($this->cookieJar)) {
         $this->cookieJar->store(array('name' => $name, 'value' => $value), $this->url);
     } else {
         $cookie = $name . '=' . $value;
         if (preg_match(self::REGEXP_INVALID_COOKIE, $cookie)) {
             throw new HTTP_Request2_LogicException("Invalid cookie: '{$cookie}'", HTTP_Request2_Exception::INVALID_ARGUMENT);
         }
         $cookies = empty($this->headers['cookie']) ? '' : $this->headers['cookie'] . '; ';
         $this->setHeader('cookie', $cookies . $cookie);
     }
     return $this;
 }