本文整理汇总了PHP中Cookie::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Cookie::parse方法的具体用法?PHP Cookie::parse怎么用?PHP Cookie::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cookie
的用法示例。
在下文中一共展示了Cookie::parse方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* Parses a raw response string, including headers and body, and returns a Response object.
*
* @param string $response
*
* @return \Brick\Http\Response
*
* @throws \RuntimeException
*/
public static function parse($response)
{
$responseObject = new Response();
if (preg_match('/^HTTP\\/([0-9]\\.[0-9]) ([0-9]{3}) .*\\r\\n/', $response, $matches) == 0) {
throw new \RuntimeException('Could not parse response (error 1).');
}
list($line, $protocolVersion, $statusCode) = $matches;
$responseObject->setProtocolVersion($protocolVersion);
$responseObject->setStatusCode($statusCode);
$response = substr($response, strlen($line));
for (;;) {
$pos = strpos($response, Message::CRLF);
if ($pos === false) {
throw new \RuntimeException('Could not parse response (error 2).');
}
if ($pos == 0) {
break;
}
$header = substr($response, 0, $pos);
if (preg_match('/^(\\S+):\\s*(.*)$/', $header, $matches) == 0) {
throw new \RuntimeException('Could not parse response (error 3).');
}
list($line, $name, $value) = $matches;
if (strtolower($name) == 'set-cookie') {
$responseObject->setCookie(Cookie::parse($value));
} else {
$responseObject->addHeader($name, $value);
}
$response = substr($response, strlen($line) + 2);
}
$body = substr($response, 2);
$responseObject->setContent($body);
return $responseObject;
}
示例2: __construct
/**
* @param string $response
*/
public function __construct(string $response = null)
{
if ($response) {
$explode = explode("\r\n\r\n", $response);
// multiple query (follow redirect) take only the last request
$explode = array_slice($explode, sizeof($explode) - 2, 2);
// body
$this->body = array_pop($explode);
// headers & cookies
$headers = [];
foreach (explode("\n", implode($explode)) as $i => $header) {
$explode = explode(':', $header, 2);
$key = $this->normalizeHeader($explode[0]);
$value = isset($explode[1]) ? trim($explode[1]) : null;
if ($key == 'Set-Cookie') {
$cookie = Cookie::parse($value);
$this->cookies[$cookie->getName()] = $cookie;
} elseif (array_key_exists($key, $headers)) {
$this->headers[$key] .= ', ' . $value;
} elseif ($value) {
$this->headers[$key] = $value;
} elseif (preg_match('#HTTP/\\d+\\.\\d+ (\\d+)#', $header, $matches)) {
$this->statusCode = (int) $matches[1];
}
}
}
}
示例3: load
private function load()
{
if (file_exists($this->file)) {
$array = (array) json_decode(file_get_contents($this->file), true);
foreach ($array as $c) {
$cookie = Cookie::parse($c);
$this->add($cookie);
}
}
}
示例4: beginAt
/**
* Navigate to a relative URL
*
* @param string relative
* @param string params
* @throws unittest.AssertionFailedError
*/
public function beginAt($relative, $params = NULL, $method = HttpConstants::GET)
{
$this->dom = $this->xpath = NULL;
$this->conn->getUrl()->setPath($relative);
try {
$this->response = $this->doRequest($method, $params);
// If we get a cookie, store it for this domain and reuse it in
// subsequent requests. If cookies are used for sessioning, we
// would be creating new sessions with every request otherwise!
foreach ((array) $this->response->header('Set-Cookie') as $str) {
$cookie = Cookie::parse($str);
$this->cookies[$this->conn->getUrl()->getHost()][$cookie->getName()] = $cookie;
}
} catch (XPException $e) {
$this->response = xp::null();
$this->fail($relative, $e, NULL);
}
}
示例5: parseCookie
public function parseCookie()
{
$cookie = Cookie::parse('Bugzilla_logincookie=e9hR2sFvjX; path=/; expires=Fri, 01-Jan-2038 00:00:00 GMT; secure; HttpOnly');
$this->assertHeaderEquals('Bugzilla_logincookie=e9hR2sFvjX; expires=Fri, 01-Jan-2038 00:00:00 GMT; path=/; secure; HTTPOnly', $cookie);
}