本文整理匯總了PHP中Cookie::fromString方法的典型用法代碼示例。如果您正苦於以下問題:PHP Cookie::fromString方法的具體用法?PHP Cookie::fromString怎麽用?PHP Cookie::fromString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Cookie
的用法示例。
在下文中一共展示了Cookie::fromString方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __construct
public function __construct($storagePath)
{
if (!file_exists($storagePath)) {
$cookieFileHandle = $this->createStorageFile($storagePath);
} elseif (false === ($cookieFileHandle = @fopen($storagePath, 'r+'))) {
throw new \RuntimeException('Failed opening cookie storage file for reading: ' . $storagePath);
}
while (!feof($cookieFileHandle)) {
if ($line = fgets($cookieFileHandle)) {
$cookie = Cookie::fromString($line);
$this->store($cookie);
}
}
$this->storagePath = $storagePath;
}
示例2: updateFromSetCookie
public function updateFromSetCookie(array $setCookies, $uri = null)
{
$cookies = array();
foreach ($setCookies as $cookie) {
foreach (explode(',', $cookie) as $i => $part) {
if (0 === $i || preg_match('/^(?P<token>\\s*[0-9A-Za-z!#\\$%\\&\'\\*\\+\\-\\.^_`\\|~]+)=/', $part)) {
$cookies[] = ltrim($part);
} else {
$cookies[count($cookies) - 1] .= ',' . $part;
}
}
}
foreach ($cookies as $cookie) {
$this->set(Cookie::fromString($cookie, $uri));
}
}
示例3: updateFromResponse
/**
* Updates the cookie jar from a Response object.
*
* @param Symfony\Components\BrowserKit\Response $response A Response object
* @param string $url The base URL
*/
public function updateFromResponse(Response $response, $uri = null)
{
foreach ($response->getHeader('Set-Cookie', false) as $cookie) {
$this->set(Cookie::fromString($cookie), $uri);
}
}
示例4: set
/**
* {@inheritdoc}
*/
public function set($key, $values, $replace = true)
{
$uniqueKey = str_replace('_', '-', strtolower($key));
if ('set-cookie' === $uniqueKey) {
if ($replace) {
$this->cookies = array();
}
foreach ((array) $values as $cookie) {
$this->setCookie(Cookie::fromString($cookie));
}
$this->headerNames[$uniqueKey] = $key;
return;
}
$this->headerNames[$uniqueKey] = $key;
parent::set($key, $values, $replace);
// ensure the cache-control header has sensible defaults
if (in_array($uniqueKey, array('cache-control', 'etag', 'last-modified', 'expires'))) {
$computed = $this->computeCacheControlValue();
$this->headers['cache-control'] = array($computed);
$this->headerNames['cache-control'] = 'Cache-Control';
$this->computedCacheControl = $this->parseCacheControl($computed);
}
}
示例5: getResponseCookies
/**
* Get HTTP response cookies
*
* @param $deleted boolean if true, get deleted cookies too
* @return Cookie[]
*/
public function getResponseCookies($deleted = true)
{
$cookies = [];
foreach ($this->response_headers as $header) {
$pos = strpos($header, ': ');
if ($pos !== false) {
$name = substr($header, 0, $pos);
$value = substr($header, $pos + 2);
if ($name == 'Set-Cookie') {
$cookie = new Cookie();
$cookie->fromString($value);
if ($deleted || !($cookie->value == 'deleted')) {
$cookies[] = $cookie;
}
}
}
}
return $cookies;
}