summaryrefslogtreecommitdiff
path: root/vendor/symfony/http-foundation/Cookie.php
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@webtrees.net>2018-12-01 17:57:53 +0000
committerGreg Roach <fisharebest@webtrees.net>2018-12-01 18:56:03 +0000
commite70f282ef978b175c5529f439f3b572c5b8531a2 (patch)
treecc022e973d89a5507dcbb35561ef93852c551dff /vendor/symfony/http-foundation/Cookie.php
parentc16be598f1a8d42127bd64c4878bd92297e18f3b (diff)
downloadwebtrees-e70f282ef978b175c5529f439f3b572c5b8531a2.tar.gz
webtrees-e70f282ef978b175c5529f439f3b572c5b8531a2.tar.bz2
webtrees-e70f282ef978b175c5529f439f3b572c5b8531a2.zip
Update minimum version of PHP to 7.1
Diffstat (limited to 'vendor/symfony/http-foundation/Cookie.php')
-rw-r--r--vendor/symfony/http-foundation/Cookie.php72
1 files changed, 39 insertions, 33 deletions
diff --git a/vendor/symfony/http-foundation/Cookie.php b/vendor/symfony/http-foundation/Cookie.php
index c38aa409da..7aab318ccd 100644
--- a/vendor/symfony/http-foundation/Cookie.php
+++ b/vendor/symfony/http-foundation/Cookie.php
@@ -27,6 +27,7 @@ class Cookie
protected $httpOnly;
private $raw;
private $sameSite;
+ private $secureDefault = false;
const SAMESITE_LAX = 'lax';
const SAMESITE_STRICT = 'strict';
@@ -50,34 +51,25 @@ class Cookie
'raw' => !$decode,
'samesite' => null,
);
- foreach (explode(';', $cookie) as $part) {
- if (false === strpos($part, '=')) {
- $key = trim($part);
- $value = true;
- } else {
- list($key, $value) = explode('=', trim($part), 2);
- $key = trim($key);
- $value = trim($value);
- }
- if (!isset($data['name'])) {
- $data['name'] = $decode ? urldecode($key) : $key;
- $data['value'] = true === $value ? null : ($decode ? urldecode($value) : $value);
- continue;
- }
- switch ($key = strtolower($key)) {
- case 'name':
- case 'value':
- break;
- case 'max-age':
- $data['expires'] = time() + (int) $value;
- break;
- default:
- $data[$key] = $value;
- break;
- }
+
+ $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;
+
+ if (isset($data['max-age'])) {
+ $data['expires'] = time() + (int) $data['max-age'];
}
- return new static($data['name'], $data['value'], $data['expires'], $data['path'], $data['domain'], $data['secure'], $data['httponly'], $data['raw'], $data['samesite']);
+ return new static($name, $value, $data['expires'], $data['path'], $data['domain'], $data['secure'], $data['httponly'], $data['raw'], $data['samesite']);
+ }
+
+ public static function create(string $name, string $value = null, $expire = 0, ?string $path = '/', string $domain = null, bool $secure = null, bool $httpOnly = true, bool $raw = false, ?string $sameSite = self::SAMESITE_LAX): self
+ {
+ return new self($name, $value, $expire, $path, $domain, $secure, $httpOnly, $raw, $sameSite);
}
/**
@@ -86,15 +78,19 @@ class Cookie
* @param int|string|\DateTimeInterface $expire The time the cookie expires
* @param string $path The path on the server in which the cookie will be available on
* @param string|null $domain The domain that the cookie is available to
- * @param bool $secure Whether the cookie should only be transmitted over a secure HTTPS connection from the client
+ * @param bool|null $secure Whether the client should send back the cookie only over HTTPS or null to auto-enable this when the request is already using HTTPS
* @param bool $httpOnly Whether the cookie will be made accessible only through the HTTP protocol
* @param bool $raw Whether the cookie value should be sent with no url encoding
* @param string|null $sameSite Whether the cookie will be available for cross-site requests
*
* @throws \InvalidArgumentException
*/
- public function __construct($name, $value = null, $expire = 0, $path = '/', $domain = null, $secure = false, $httpOnly = true, $raw = false, $sameSite = null)
+ public function __construct(string $name, string $value = null, $expire = 0, ?string $path = '/', string $domain = null, ?bool $secure = false, bool $httpOnly = true, bool $raw = false, string $sameSite = null)
{
+ if (9 > \func_num_args()) {
+ @trigger_error(sprintf('The default value of the "$secure" and "$samesite" arguments of "%s"\'s constructor will respectively change from "false" to "null" and from "null" to "lax" in Symfony 5.0, you should define their values explicitly or use "Cookie::create()" instead.', __METHOD__), E_USER_DEPRECATED);
+ }
+
// from PHP source code
if (preg_match("/[=,; \t\r\n\013\014]/", $name)) {
throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $name));
@@ -120,11 +116,13 @@ class Cookie
$this->domain = $domain;
$this->expire = 0 < $expire ? (int) $expire : 0;
$this->path = empty($path) ? '/' : $path;
- $this->secure = (bool) $secure;
- $this->httpOnly = (bool) $httpOnly;
- $this->raw = (bool) $raw;
+ $this->secure = $secure;
+ $this->httpOnly = $httpOnly;
+ $this->raw = $raw;
- if (null !== $sameSite) {
+ if ('' === $sameSite) {
+ $sameSite = null;
+ } elseif (null !== $sameSite) {
$sameSite = strtolower($sameSite);
}
@@ -246,7 +244,7 @@ class Cookie
*/
public function isSecure()
{
- return $this->secure;
+ return $this->secure ?? $this->secureDefault;
}
/**
@@ -288,4 +286,12 @@ class Cookie
{
return $this->sameSite;
}
+
+ /**
+ * @param bool $default The default value of the "secure" flag when it is set to null
+ */
+ public function setSecureDefault(bool $default): void
+ {
+ $this->secureDefault = $default;
+ }
}