Skip to content

Commit 16b8de9

Browse files
authored
Added partitioned support for Cookie (#6971)
1 parent 67acc83 commit 16b8de9

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/Cookie/Cookie.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public function __construct(
5252
protected bool $secure = false,
5353
protected bool $httpOnly = true,
5454
protected bool $raw = false,
55-
?string $sameSite = null
55+
?string $sameSite = null,
56+
protected bool $partitioned = false
5657
) {
5758
// from PHP source code
5859
if (preg_match("/[=,; \t\r\n\013\014]/", $name)) {
@@ -130,6 +131,10 @@ public function __toString()
130131
$str .= '; samesite=' . $this->getSameSite();
131132
}
132133

134+
if ($this->isPartitioned()) {
135+
$str .= '; partitioned';
136+
}
137+
133138
return $str;
134139
}
135140

@@ -146,6 +151,7 @@ public static function fromString(string $cookie, bool $decode = false): self
146151
'httponly' => false,
147152
'raw' => ! $decode,
148153
'samesite' => null,
154+
'partitioned' => false,
149155
];
150156
foreach (explode(';', $cookie) as $part) {
151157
if (! str_contains($part, '=')) {
@@ -183,7 +189,8 @@ public static function fromString(string $cookie, bool $decode = false): self
183189
$data['secure'],
184190
$data['httponly'],
185191
$data['raw'],
186-
$data['samesite']
192+
$data['samesite'],
193+
$data['partitioned']
187194
);
188195
}
189196

@@ -274,4 +281,12 @@ public function getSameSite(): ?string
274281
{
275282
return $this->sameSite;
276283
}
284+
285+
/**
286+
* Checks whether the cookie should be tied to the top-level site in cross-site context.
287+
*/
288+
public function isPartitioned(): bool
289+
{
290+
return $this->partitioned;
291+
}
277292
}

0 commit comments

Comments
 (0)