getScheme() === "https"; } /** * @return bool */ protected function isHttpOnly(): bool { return true; } /** * @return string */ protected function getSameSite(): string { return "Lax"; } public function __construct() { $this->value = $_COOKIE[$this->getKey()] ?? null; } /** * @param string $value * @return bool */ public function set(string $value): bool { $options = [ 'expires' => $this->getMaxAge() !== null ? time() + $this->getMaxAge() : 0, 'path' => $this->getPath(), 'domain' => $this->getDomain(), 'secure' => $this->isSecure(), 'httponly' => $this->isHttpOnly(), 'samesite' => $this->getSameSite() ]; $result = setcookie( $this->getKey(), $value, $options ); if ($result) { $this->value = $value; } return $result; } /** * @return bool */ public function delete(): bool { $options = [ 'expires' => time() - 3600, 'path' => $this->getPath(), 'domain' => $this->getDomain(), 'secure' => $this->isSecure(), 'httponly' => $this->isHttpOnly(), 'samesite' => $this->getSameSite() ]; $result = setcookie( $this->getKey(), '', $options ); if ($result) { $this->value = null; } return $result; } /** * @return string|null */ public function getValue(): ?string { return $this->value; } /** * @return bool */ public function exists(): bool { return $this->getValue() !== null; } }