39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
|
<?php
|
||
|
include_once "Reflection.php";
|
||
|
class RequestHeader {
|
||
|
use ReflectionHook;
|
||
|
static $_attributes = [];
|
||
|
static $readyHeaders = false;
|
||
|
function __construct()
|
||
|
{
|
||
|
if(!RequestHeader::$readyHeaders)
|
||
|
{
|
||
|
foreach ($_SERVER as $name => $value)
|
||
|
{
|
||
|
if (substr($name, 0, 5) == 'HTTP_')
|
||
|
{
|
||
|
RequestHeader::$_attributes[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
public static function get($name)
|
||
|
{
|
||
|
return (new static)->{$name};
|
||
|
}
|
||
|
public static function set($name, $value)
|
||
|
{
|
||
|
$requestHeader = new static;
|
||
|
$requestHeader->{$name} = $value;
|
||
|
}
|
||
|
function setAttribute($name, $value)
|
||
|
{
|
||
|
$formarly = ucfirst(strtolower($name));
|
||
|
header("$formarly: $value");
|
||
|
}
|
||
|
function getAttribute($name)
|
||
|
{
|
||
|
$formarly = ucfirst(strtolower($name));
|
||
|
return RequestHeader::$_attributes[$formarly] ?? null;
|
||
|
}
|
||
|
};
|