function Cookie::fromString
Same name in this branch
- 11.1.x vendor/symfony/browser-kit/Cookie.php \Symfony\Component\BrowserKit\Cookie::fromString()
Creates cookie from raw header string.
2 calls to Cookie::fromString()
- HttpFoundationFactory::createResponse in vendor/
symfony/ psr-http-message-bridge/ Factory/ HttpFoundationFactory.php - Creates a Symfony Response instance from a PSR-7 one.
- ResponseHeaderBag::set in vendor/
symfony/ http-foundation/ ResponseHeaderBag.php - Sets a header by name.
File
-
vendor/
symfony/ http-foundation/ Cookie.php, line 38
Class
- Cookie
- Represents a cookie.
Namespace
Symfony\Component\HttpFoundationCode
public static function fromString(string $cookie, bool $decode = false) : static {
$data = [
'expires' => 0,
'path' => '/',
'domain' => null,
'secure' => false,
'httponly' => false,
'raw' => !$decode,
'samesite' => null,
'partitioned' => false,
];
$parts = HeaderUtils::split($cookie, ';=');
$part = array_shift($parts);
$name = $decode ? urldecode($part[0]) : $part[0];
$value = isset($part[1]) ? $decode ? urldecode($part[1]) : $part[1] : null;
$data = HeaderUtils::combine($parts) + $data;
$data['expires'] = self::expiresTimestamp($data['expires']);
if (isset($data['max-age']) && ($data['max-age'] > 0 || $data['expires'] > time())) {
$data['expires'] = time() + (int) $data['max-age'];
}
return new static($name, $value, $data['expires'], $data['path'], $data['domain'], $data['secure'], $data['httponly'], $data['raw'], $data['samesite'], $data['partitioned']);
}