コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
ファイル: CookiePool.php プロジェクト: jivoo/http
 /**
  * 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()));
     }
 }
コード例 #3
0
ファイル: CookieTest.php プロジェクト: seytar/psx
 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());
 }
コード例 #4
0
ファイル: HttpTrait.php プロジェクト: cawaphp/cawa
 /**
  * @param Cookie $cookie
  */
 public function clearCookie(Cookie $cookie)
 {
     $cookie->setExpire(1);
     $this->cookies[$cookie->getName()] = $cookie;
 }
コード例 #5
0
 public function addCookie(Cookie $cookie)
 {
     $this->cookies[$cookie->getName()] = $cookie;
 }
コード例 #6
0
ファイル: CookieJar.php プロジェクト: pgodel/PageRoller
 /**
  * Sets a cookie.
  *
  * @param Symfony\Components\BrowserKit\Cookie $cookie A Cookie instance
  */
 public function set(Cookie $cookie)
 {
     $this->cookieJar[$cookie->getName()] = $cookie;
 }
コード例 #7
0
ファイル: CookieJar.php プロジェクト: rouffj/symfony
 /**
  * Sets a cookie.
  *
  * @param Cookie $cookie A Cookie instance
  *
  * @api
  */
 public function set(Cookie $cookie)
 {
     $this->cookieJar[$cookie->getDomain()][$cookie->getPath()][$cookie->getName()] = $cookie;
 }
コード例 #8
0
 /**
  * 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;
 }
コード例 #9
0
 /**
  * Deletes a cookie.
  * 
  * @param  Cookie $cookie
  * @return void
  */
 public function deleteCookie(Cookie $cookie)
 {
     $cookie->setValue('');
     $cookie->setMaxAge(-1);
     $this->cookies[$cookie->getName()] = $cookie;
 }
コード例 #10
0
ファイル: ResponseHeaderBag.php プロジェクト: symfony/symfony
 /**
  * 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';
 }
コード例 #11
0
ファイル: ArrayCookieJar.php プロジェクト: amphp/artax
 /**
  * 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()]);
 }
コード例 #12
0
ファイル: CookieStorage.php プロジェクト: reshadf/RMProject
 /**
  * Get cookie.
  */
 public function get(Cookie $cookie)
 {
     return $_COOKIE[$cookie->getName()];
 }
コード例 #13
0
 private function assertCookieNameAndValue(Cookie $cookie, $expectedName, $expectedValue)
 {
     $this->assertEquals($expectedName, $cookie->getName());
     $this->assertEquals($expectedValue, $cookie->getValue());
 }
コード例 #14
0
ファイル: CookieJar.php プロジェクト: phpf/http
 public function add(Cookie $cookie)
 {
     $this->cookies[$cookie->getName()] = $cookie;
     return $this;
 }
コード例 #15
0
 /**
  * @param Cookie $cookie
  * @return Cookies
  */
 public function with(Cookie $cookie)
 {
     $clone = clone $this;
     $clone->cookies[$cookie->getName()] = $cookie;
     return $clone;
 }
コード例 #16
0
 /**
  * Remove a cookie
  * @param Nearsoft\SeleniumClient\Cookie $cookie
  */
 public function deleteCookie(Cookie $cookie)
 {
     $this->deleteCookieNamed($cookie->getName());
 }