microphp/Core/RequestHeader.php

39 lines
1.2 KiB
PHP
Raw Normal View History

2023-04-02 10:00:20 +03:00
<?php
include_once "Reflection.php";
class RequestHeader {
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(!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;
}
2023-04-02 14:10:58 +03:00
public function setAttribute($name, $value)
2023-04-02 10:00:20 +03:00
{
$formarly = ucfirst(strtolower($name));
header("$formarly: $value");
}
2023-04-02 14:10:58 +03:00
public function getAttribute($name)
2023-04-02 10:00:20 +03:00
{
$formarly = ucfirst(strtolower($name));
return RequestHeader::$_attributes[$formarly] ?? null;
}
};