Skip to content

Commit

Permalink
fix: only serialize defined cookie parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
yanbuatois authored and gulien committed Apr 11, 2024
1 parent d208bfa commit e088257
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/Modules/ChromiumCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Gotenberg\Modules;

class ChromiumCookie
use JsonSerializable;

class ChromiumCookie implements JsonSerializable
{
public function __construct(
public readonly string $name,
Expand All @@ -16,4 +18,32 @@ public function __construct(
public readonly string|null $sameSite = null,
) {
}

/** @return array<string, string|bool> */
public function jsonSerialize(): array
{
$serialized = [
'name' => $this->name,
'value' => $this->value,
'domain' => $this->domain,
];

if ($this->path !== null) {
$serialized['path'] = $this->path;
}

if ($this->secure !== null) {
$serialized['secure'] = $this->secure;
}

if ($this->httpOnly !== null) {
$serialized['httpOnly'] = $this->httpOnly;
}

if ($this->sameSite !== null) {
$serialized['sameSite'] = $this->sameSite;
}

return $serialized;
}
}

0 comments on commit e088257

Please sign in to comment.