Core MVC, HTTP client, Session, Cookie, Config, HTTPException — 111 PHPUnit tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* @package Bicycle
|
|
* @author Egor Isaev
|
|
* @description Cookie.php
|
|
* @copyright (c) 04/06/2026
|
|
*/
|
|
|
|
namespace System\Classes;
|
|
|
|
class Cookie
|
|
{
|
|
public static int $expiration = 0;
|
|
public static string $path = '/';
|
|
public static ?string $domain = null;
|
|
public static bool $secure = false;
|
|
public static bool $httponly = true;
|
|
public static string $samesite = 'Lax';
|
|
|
|
public static function get(string $key, ?string $default = null): ?string
|
|
{
|
|
return $_COOKIE[$key] ?? $default;
|
|
}
|
|
|
|
public static function set(string $name, string $value, ?int $lifetime = null): bool
|
|
{
|
|
$lifetime = $lifetime ?? self::$expiration;
|
|
$expires = $lifetime > 0 ? time() + $lifetime : 0;
|
|
|
|
return setcookie($name, $value, [
|
|
'expires' => $expires,
|
|
'path' => self::$path,
|
|
'domain' => self::$domain,
|
|
'secure' => self::$secure,
|
|
'httponly' => self::$httponly,
|
|
'samesite' => self::$samesite,
|
|
]);
|
|
}
|
|
|
|
public static function delete(string $name): bool
|
|
{
|
|
unset($_COOKIE[$name]);
|
|
|
|
return setcookie($name, '', [
|
|
'expires' => 1,
|
|
'path' => self::$path,
|
|
'domain' => self::$domain,
|
|
'secure' => self::$secure,
|
|
'httponly' => self::$httponly,
|
|
'samesite' => self::$samesite,
|
|
]);
|
|
}
|
|
}
|