本文整理汇总了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;
}