|
12 | 12 | */ |
13 | 13 | final class Cookie implements Stringable |
14 | 14 | { |
| 15 | + /** |
| 16 | + * @param null|int $maxAge The maximum age of the cookie in seconds. This is an alternative to the expiration date. If set, the cookie will expire after the specified number of seconds. |
| 17 | + * @param null|string $domain This specifies the domain for which the cookie is valid. If set, the cookie will be sent to this domain and its subdomains. If `null`, it defaults to the current domain. |
| 18 | + * @param null|string $path The URL path that must exist in the requested URL for the cookie to be sent. If set, the cookie will only be sent for requests to this path and its subdirectories. |
| 19 | + * @param null|bool $secure When `true`, this cookie is only transmitted over secure connections. |
| 20 | + * @param null|bool $httpOnly When `true`, this cookie will not be accessible using JavaScript. |
| 21 | + * @param null|SameSite $sameSite See {@see \Tempest\Http\Cookie\SameSite}. |
| 22 | + */ |
15 | 23 | public function __construct( |
16 | 24 | public string $key, |
17 | | - public string $value = '', |
| 25 | + public ?string $value = null, |
18 | 26 | public DateTimeInterface|int|null $expiresAt = null, |
19 | 27 | public ?int $maxAge = null, |
20 | 28 | public ?string $domain = null, |
21 | | - public ?string $path = null, |
22 | | - public ?bool $secure = null, |
23 | | - public ?bool $httpOnly = null, |
| 29 | + public ?string $path = '/', |
| 30 | + public bool $secure = false, |
| 31 | + public bool $httpOnly = false, |
24 | 32 | public ?SameSite $sameSite = null, |
25 | 33 | ) {} |
26 | 34 |
|
27 | 35 | public function __toString(): string |
28 | 36 | { |
29 | 37 | $parts = [ |
30 | | - $this->key . '=' . rawurlencode($this->value), |
| 38 | + $this->key . '=' . rawurlencode($this->value ?? ''), |
31 | 39 | ]; |
32 | 40 |
|
33 | 41 | if ($expiresAt = $this->getExpiresAtTime()) { |
|
0 commit comments