diff --git a/src/Modules/ChromiumCookie.php b/src/Modules/ChromiumCookie.php index a763477..76388b0 100644 --- a/src/Modules/ChromiumCookie.php +++ b/src/Modules/ChromiumCookie.php @@ -4,7 +4,9 @@ namespace Gotenberg\Modules; -class ChromiumCookie +use JsonSerializable; + +class ChromiumCookie implements JsonSerializable { public function __construct( public readonly string $name, @@ -16,4 +18,32 @@ public function __construct( public readonly string|null $sameSite = null, ) { } + + /** @return array */ + 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; + } }