public static function SetCookie::fromString in Lockr 7.3
Create a new SetCookie object from a string
Parameters
string $cookie Set-Cookie header string:
Return value
self
1 call to SetCookie::fromString()
- CookieJar::extractCookies in vendor/
guzzlehttp/ guzzle/ src/ Cookie/ CookieJar.php - Extract cookies from an HTTP response and store them in the CookieJar.
File
- vendor/
guzzlehttp/ guzzle/ src/ Cookie/ SetCookie.php, line 32
Class
- SetCookie
- Set-Cookie object
Namespace
GuzzleHttp\CookieCode
public static function fromString($cookie) {
// Create the default return array
$data = self::$defaults;
// Explode the cookie string using a series of semicolons
$pieces = array_filter(array_map('trim', explode(';', $cookie)));
// The name of the cookie (first kvp) must exist and include an equal sign.
if (empty($pieces[0]) || !strpos($pieces[0], '=')) {
return new self($data);
}
// Add the cookie pieces into the parsed data array
foreach ($pieces as $part) {
$cookieParts = explode('=', $part, 2);
$key = trim($cookieParts[0]);
$value = isset($cookieParts[1]) ? trim($cookieParts[1], " \n\r\t\0\v") : true;
// Only check for non-cookies when cookies have been found
if (empty($data['Name'])) {
$data['Name'] = $key;
$data['Value'] = $value;
}
else {
foreach (array_keys(self::$defaults) as $search) {
if (!strcasecmp($search, $key)) {
$data[$search] = $value;
continue 2;
}
}
$data[$key] = $value;
}
}
return new self($data);
}