proxitok/app/Helpers/Cookies.php

41 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2022-01-30 18:02:52 -05:00
namespace App\Helpers;
2022-09-25 13:53:00 -04:00
use App\Constants\Themes;
2022-09-25 13:53:00 -04:00
class Cookies {
static public function get(string $name, string $default_value = ''): string {
if (isset($_COOKIE[$name]) && !empty($_COOKIE[$name])) {
return $_COOKIE[$name];
}
return $default_value;
}
static public function theme(): string {
$theme = self::get('theme');
2022-09-25 13:53:00 -04:00
$ref = new \ReflectionClass(Themes::class);
$themes = $ref->getConstants();
if ($theme && in_array($theme, $themes)) {
return $theme;
}
return 'default';
}
2022-09-25 13:53:00 -04:00
static public function downloader(): string {
$downloader = self::get('api-downloader', 'default');
return $downloader;
}
static public function exists(string $name): bool {
return isset($_COOKIE[$name]);
}
2022-06-28 14:41:51 -04:00
static public function check(string $name, string $value): bool {
return self::exists($name) && $_COOKIE[$name] === $value;
}
static public function set(string $name, string $value) {
2022-01-28 09:54:09 -05:00
setcookie($name, $value, time()+60*60*24*30, '/', '', isset($_SERVER['HTTPS']), true);
}
};