update patch 1
This commit is contained in:
+14
-18
@@ -22,17 +22,10 @@ class Cookie
|
||||
public const SAMESITE_LAX = 'lax';
|
||||
public const SAMESITE_STRICT = 'strict';
|
||||
|
||||
protected string $name;
|
||||
protected ?string $value;
|
||||
protected ?string $domain;
|
||||
protected int $expire;
|
||||
protected string $path;
|
||||
protected ?bool $secure;
|
||||
protected bool $httpOnly;
|
||||
|
||||
private bool $raw;
|
||||
private ?string $sameSite = null;
|
||||
private bool $partitioned = false;
|
||||
private bool $secureDefault = false;
|
||||
|
||||
private const RESERVED_CHARS_LIST = "=,; \t\r\n\v\f";
|
||||
@@ -94,27 +87,30 @@ class Cookie
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct(string $name, ?string $value = null, int|string|\DateTimeInterface $expire = 0, ?string $path = '/', ?string $domain = null, ?bool $secure = null, bool $httpOnly = true, bool $raw = false, ?string $sameSite = self::SAMESITE_LAX, bool $partitioned = false)
|
||||
{
|
||||
public function __construct(
|
||||
protected string $name,
|
||||
protected ?string $value = null,
|
||||
int|string|\DateTimeInterface $expire = 0,
|
||||
?string $path = '/',
|
||||
protected ?string $domain = null,
|
||||
protected ?bool $secure = null,
|
||||
protected bool $httpOnly = true,
|
||||
private bool $raw = false,
|
||||
?string $sameSite = self::SAMESITE_LAX,
|
||||
private bool $partitioned = false,
|
||||
) {
|
||||
// from PHP source code
|
||||
if ($raw && false !== strpbrk($name, self::RESERVED_CHARS_LIST)) {
|
||||
throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $name));
|
||||
throw new \InvalidArgumentException(\sprintf('The cookie name "%s" contains invalid characters.', $name));
|
||||
}
|
||||
|
||||
if (!$name) {
|
||||
throw new \InvalidArgumentException('The cookie name cannot be empty.');
|
||||
}
|
||||
|
||||
$this->name = $name;
|
||||
$this->value = $value;
|
||||
$this->domain = $domain;
|
||||
$this->expire = self::expiresTimestamp($expire);
|
||||
$this->path = $path ?: '/';
|
||||
$this->secure = $secure;
|
||||
$this->httpOnly = $httpOnly;
|
||||
$this->raw = $raw;
|
||||
$this->sameSite = $this->withSameSite($sameSite)->sameSite;
|
||||
$this->partitioned = $partitioned;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,7 +204,7 @@ class Cookie
|
||||
public function withRaw(bool $raw = true): static
|
||||
{
|
||||
if ($raw && false !== strpbrk($this->name, self::RESERVED_CHARS_LIST)) {
|
||||
throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $this->name));
|
||||
throw new \InvalidArgumentException(\sprintf('The cookie name "%s" contains invalid characters.', $this->name));
|
||||
}
|
||||
|
||||
$cookie = clone $this;
|
||||
|
||||
Reference in New Issue
Block a user