public function build($name, $value) { $cookie = new HttpCookie($name, $value); $cookie->setPath($this->defaultPath); $cookie->setSecure($this->defaultSecure); $cookie->setHttpOnly($this->defaultHttpOnly); if ($this->defaultDomain !== null) { $cookie->setDomain($this->defaultDomain); } return $cookie; }
/** * Set a cookie * * @param HttpCookie $aCookie * The cookie to set * * @return boolean */ public function setCookie(HttpCookie $aCookie) { assert('$aCookie->getPath() !== null && $aCookie->getPath() !== ""'); $result = setcookie($aCookie->getName(), self::encode($aCookie->getValue()), $aCookie->getExpire(), $aCookie->getPath(), $aCookie->getDomain(), $aCookie->getSecure(), $aCookie->getHttponly()); if ($result === true) { $this->storedCookies[$aCookie->getName()] = $aCookie; } return $result; }
public function testHttpCookieToStringMethodWithBooleanFalseAsValue() { $cookie = new HttpCookie('testCookie'); $cookie->setValue(false); $this->assertSame($cookie->__toString(), 'testCookie=0; Path=/; HttpOnly'); }
/** * Parses the http set cookie header * * @param string $headerValue The header value with cookie info in it * * @return void */ public function parseCookieHeaderValue($headerValue) { $request = $this->getRequest(); // parse cookies and iterate over foreach (explode(';', $headerValue) as $cookieStr) { // check if cookieStr is no just a empty str if (strlen($cookieStr) > 0) { // add cookie object to request $request->addCookie(HttpCookie::createFromRawSetCookieHeader($cookieStr)); } } }
/** * Adds a HttpCookie to the cookie collection. * * @method add * @param HttpCookie $httpCookie */ public function add(HttpCookie $httpCookie) { if (is_string($httpCookie->getName())) { $this->collection[$httpCookie->getName()] = $httpCookie; } }