microphp/Core/RequestCookie.php

28 lines
850 B
PHP
Raw Permalink Normal View History

2023-04-02 10:00:20 +03:00
<?php
include_once "Reflection.php";
class RequestCookie {
use ReflectionHook;
static $_attributes = [];
static $readyHeaders = false;
2023-04-02 14:10:58 +03:00
public function __construct()
2023-04-02 10:00:20 +03:00
{
if(!RequestCookie::$readyHeaders)
{
RequestCookie::$_attributes = (array) $_COOKIE;
};
}
2023-04-02 14:10:58 +03:00
public function setAttribute($name, $value, $time = '+1 years')
2023-04-02 10:00:20 +03:00
{
$formarly = strtolower($name);
setcookie($name, $value, strtotime( $time ));
}
2023-04-02 14:10:58 +03:00
public function getAttribute($name)
2023-04-02 10:00:20 +03:00
{
$formarly = strtolower($name);
return RequestCookie::$_attributes[$formarly];
}
2023-04-02 14:10:58 +03:00
public function removeAttribute($name)
2023-04-02 10:00:20 +03:00
{
$this->setAttribute($name, 0, "-1 days");
}
};