fromString() публичный статический метод

Creates a Cookie instance from a Set-Cookie header value.
public static fromString ( string $cookie, string $url = null ) : Cookie
$cookie string A Set-Cookie header value
$url string The base URL
Результат Cookie A Cookie instance
 /**
  * Parse the standard `Header-name: value' headers into
  * individual header name/value pairs
  *
  * @param string $header
  */
 private function parseHeader($header)
 {
     if (empty($header)) {
         return;
     }
     $pos = strpos($header, ": ");
     if (false !== $pos) {
         $name = trim(substr($header, 0, $pos));
         $value = substr($header, $pos + 2);
         if (strtolower($name) == "set-cookie") {
             $cookie = CookieParser::fromString($value);
             $this->cookies[] = new Cookie($cookie->getName(), $cookie->getRawValue(), (int) $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
         } else {
             $this->headers[$name] = $value;
         }
     }
 }
Пример #2
2
 /**
  * {@inheritdoc}
  */
 public function updateFromResponse(Response $response, $uri = null)
 {
     foreach ($response->getHeader('Set-Cookie', false) as $cookie) {
         $this->set(Cookie::fromString(urldecode($cookie), $uri));
     }
 }
Пример #3
0
 /**
  * @dataProvider getExpireCookieStrings
  */
 public function testFromStringAcceptsSeveralExpiresDateFormats($cookie)
 {
     $this->assertEquals(1596185377, Cookie::fromString($cookie)->getExpiresTime());
 }
Пример #4
0
 public function testFromStringWithCapitalization()
 {
     $this->assertEquals('Foo=Bar; path=/', (string) Cookie::fromString('Foo=Bar'));
     $this->assertEquals('foo=bar; expires=Fri, 31 Dec 2010 23:59:59 GMT; path=/', (string) Cookie::fromString('foo=bar; Expires=Fri, 31 Dec 2010 23:59:59 GMT'));
     $this->assertEquals('foo=bar; domain=www.example.org; path=/; httponly', (string) Cookie::fromString('foo=bar; DOMAIN=www.example.org; HttpOnly'));
 }
Пример #5
0
 public function testFromStringThrowsAnExceptionIfUrlIsNotValid()
 {
     $this->setExpectedException('InvalidArgumentException');
     Cookie::fromString('foo=bar', 'foobar');
 }
Пример #6
0
 /**
  * @dataProvider getTestsForToFromString
  */
 public function testToFromString($cookie)
 {
     $this->assertEquals($cookie, (string) Cookie::fromString($cookie));
 }