/**
  * Add a cookie to the class. Cookie should be passed either as a Zend\Http\Header\Cookie object
  * or as a string - in which case an object is created from the string.
  *
  * @param Cookie|string $cookie
  * @param Uri\Uri|string    $refUri Optional reference URI (for domain, path, secure)
  * @throws Exception\InvalidArgumentException
  */
 public function addCookie(Cookie $cookie, $refUri = null)
 {
     if (is_string($cookie)) {
         $cookie = Cookie::fromString($cookie, $refUri);
     }
     if ($cookie instanceof Cookie) {
         $domain = $cookie->getDomain();
         $path = $cookie->getPath();
         if (!isset($this->cookies[$domain])) {
             $this->cookies[$domain] = array();
         }
         if (!isset($this->cookies[$domain][$path])) {
             $this->cookies[$domain][$path] = array();
         }
         $this->cookies[$domain][$path][$cookie->getName()] = $cookie;
         $this->rawCookies[] = $cookie;
     } else {
         throw new Exception\InvalidArgumentException('Supplient argument is not a valid cookie string or object');
     }
 }
Beispiel #2
0
 public function testCookieFromStringCreatesValidCookieHeadersWithMultipleValues()
 {
     $cookieHeader = Cookie::fromString('Cookie: name=value; foo=bar');
     $this->assertEquals('value', $cookieHeader->name);
     $this->assertEquals('bar', $cookieHeader['foo']);
 }