/** * Add a cookie header to the response * * No need to have more classes for this, simply alter the headers to include the Set-Cookie: header. * * @param $name * @param null $value * @param null $expires * @param null $path * @param null $domain * @param bool|false $secure * @param bool|false $httpOnly * * @return Response */ public function withCookie($cookie, $value = '', $expires = null, $path = '/', $domain = null, $secure = false, $httpOnly = true) { //transform it into a cookie instance if (!$cookie instanceof Cookie) { $cookie = new Cookie($cookie, $value, $expires, $path, $domain, $secure, $httpOnly); } //save it in the cookies array $this->cookies[$cookie->getName()] = $cookie; $this->cookieNames[$cookie->getName()] = $cookie->getName(); //get current cookie headers $cookieHeaders = $this->getHeader('Set-Cookie'); //get a response object without the cookies $temp = $this->withoutHeader('Set-Cookie'); //replace if already set $exists = false; foreach ($cookieHeaders as $index => $cookieString) { if (substr($cookieString, 0, strlen($cookie->getName()) + 1) === $cookie->getName() . '=') { $cookieHeaders[$index] = (string) $cookie; $exists = true; break; } } //append if not already set if (false === $exists) { $cookieHeaders[] = (string) $cookie; } $response = $temp->withHeader('Set-Cookie', $cookieHeaders); //return new instance return $response; }
/** * Add a cookie to the pool. * * @param Cookie $cookie A cookie. */ public function add(Cookie $cookie) { if ($cookie instanceof MutableCookie) { $this->cookies[$cookie->getName()] = $cookie; } elseif ($cookie instanceof ResponseCookie) { $this[$cookie->getName()]->set($cookie->get())->setPath($cookie->getPath())->setDomain($cookie->getDomain())->setSecure($cookie->isSecure())->setHttpOnly($cookie->isHttpOnly())->expiresAt($cookie->getExpiration()); } else { $this->cookies[$cookie->getName()] = $this->setDefaults(new MutableCookie($cookie->getName(), $cookie->get())); } }
public function testCookie() { $cookie = new Cookie('DNR=deleted; expires=Tue, 24-Dec-2013 11:39:14 GMT; path=/; domain=.www.yahoo.com'); $this->assertEquals('DNR', $cookie->getName()); $this->assertEquals('deleted', $cookie->getValue()); $this->assertEquals(date('r', strtotime('Tue, 24-Dec-2013 11:39:14 GMT')), $cookie->getExpires()->format('r')); $this->assertEquals('/', $cookie->getPath()); $this->assertEquals('www.yahoo.com', $cookie->getDomain()); }
/** * @param Cookie $cookie */ public function clearCookie(Cookie $cookie) { $cookie->setExpire(1); $this->cookies[$cookie->getName()] = $cookie; }
public function addCookie(Cookie $cookie) { $this->cookies[$cookie->getName()] = $cookie; }
/** * Sets a cookie. * * @param Symfony\Components\BrowserKit\Cookie $cookie A Cookie instance */ public function set(Cookie $cookie) { $this->cookieJar[$cookie->getName()] = $cookie; }
/** * Sets a cookie. * * @param Cookie $cookie A Cookie instance * * @api */ public function set(Cookie $cookie) { $this->cookieJar[$cookie->getDomain()][$cookie->getPath()][$cookie->getName()] = $cookie; }
/** * Add cookie * * @param scriptlet.Cookie cookie * @return scriptlet.Cookie added cookie */ public function addCookie(Cookie $cookie) { $this->initCookies(); $this->cookies[$cookie->getName()] = $cookie; return $cookie; }
/** * Deletes a cookie. * * @param Cookie $cookie * @return void */ public function deleteCookie(Cookie $cookie) { $cookie->setValue(''); $cookie->setMaxAge(-1); $this->cookies[$cookie->getName()] = $cookie; }
/** * Sets a cookie. * * @param Cookie $cookie */ public function setCookie(Cookie $cookie) { $this->cookies[$cookie->getDomain()][$cookie->getPath()][$cookie->getName()] = $cookie; $this->headerNames['set-cookie'] = 'Set-Cookie'; }
/** * Remove a specific cookie from storage * * @param Cookie $cookie * @return void */ public function remove(Cookie $cookie) { unset($this->cookies[$cookie->getDomain()][$cookie->getPath()][$cookie->getName()]); }
/** * Get cookie. */ public function get(Cookie $cookie) { return $_COOKIE[$cookie->getName()]; }
private function assertCookieNameAndValue(Cookie $cookie, $expectedName, $expectedValue) { $this->assertEquals($expectedName, $cookie->getName()); $this->assertEquals($expectedValue, $cookie->getValue()); }
public function add(Cookie $cookie) { $this->cookies[$cookie->getName()] = $cookie; return $this; }
/** * @param Cookie $cookie * @return Cookies */ public function with(Cookie $cookie) { $clone = clone $this; $clone->cookies[$cookie->getName()] = $cookie; return $clone; }
/** * Remove a cookie * @param Nearsoft\SeleniumClient\Cookie $cookie */ public function deleteCookie(Cookie $cookie) { $this->deleteCookieNamed($cookie->getName()); }