Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions src/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ protected static function getConfig(string $stored): SymmetricConfig
* @param string $domain (defaults to NULL)
* @param bool $secure (defaults to TRUE)
* @param bool $httpOnly (defaults to TRUE)
* @param string $samesite (defaults to ''; PHP >= 7.3.0)
* @return bool
*
* @throws InvalidDigestLength
Expand All @@ -156,16 +157,34 @@ public function store(
string $path = '/',
string $domain = '',
bool $secure = true,
bool $httpOnly = true
bool $httpOnly = true,
string $sameSite = ''
): bool {
$val = Crypto::encrypt(
new HiddenString(
(string) \json_encode($value)
),
$this->key
);
if (\version_compare(PHP_VERSION, '7.3.0') >= 0) {
$options = [
'expires' => (int) $expire,
'path' => (string) $path,
'domain' => (string) $domain,
'secure' => (bool) $secure,
'httponly' => (bool) $httpOnly,
];
if ($sameSite !== '') {
$options['samesite'] = (string) $sameSite;
}
return \setcookie(
$name,
$val,
$options);
}
return \setcookie(
$name,
Crypto::encrypt(
new HiddenString(
(string) \json_encode($value)
),
$this->key
),
$val,
(int) $expire,
(string) $path,
(string) $domain,
Expand Down