Skip to content

Commit

Permalink
Added partitioned support for Cookie (#6971)
Browse files Browse the repository at this point in the history
  • Loading branch information
huangdijia authored Aug 15, 2024
1 parent 67acc83 commit 16b8de9
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Cookie/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public function __construct(
protected bool $secure = false,
protected bool $httpOnly = true,
protected bool $raw = false,
?string $sameSite = null
?string $sameSite = null,
protected bool $partitioned = false
) {
// from PHP source code
if (preg_match("/[=,; \t\r\n\013\014]/", $name)) {
Expand Down Expand Up @@ -130,6 +131,10 @@ public function __toString()
$str .= '; samesite=' . $this->getSameSite();
}

if ($this->isPartitioned()) {
$str .= '; partitioned';
}

return $str;
}

Expand All @@ -146,6 +151,7 @@ public static function fromString(string $cookie, bool $decode = false): self
'httponly' => false,
'raw' => ! $decode,
'samesite' => null,
'partitioned' => false,
];
foreach (explode(';', $cookie) as $part) {
if (! str_contains($part, '=')) {
Expand Down Expand Up @@ -183,7 +189,8 @@ public static function fromString(string $cookie, bool $decode = false): self
$data['secure'],
$data['httponly'],
$data['raw'],
$data['samesite']
$data['samesite'],
$data['partitioned']
);
}

Expand Down Expand Up @@ -274,4 +281,12 @@ public function getSameSite(): ?string
{
return $this->sameSite;
}

/**
* Checks whether the cookie should be tied to the top-level site in cross-site context.
*/
public function isPartitioned(): bool
{
return $this->partitioned;
}
}

0 comments on commit 16b8de9

Please sign in to comment.