29 lines
554 B
PHP
29 lines
554 B
PHP
<?php
|
|
|
|
namespace lib\Http;
|
|
|
|
class HTTP
|
|
{
|
|
protected array $headers = [];
|
|
|
|
public function __construct()
|
|
{
|
|
$this->headers = foreach ($_SERVER as $name => $value) {
|
|
if (str_starts_with($name, 'HTTP_')) {
|
|
$key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
|
|
$headers[$key] = $value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getHeaders(): array
|
|
{
|
|
return $this->headers;
|
|
}
|
|
|
|
public function getHeader(string $key): ?string
|
|
{
|
|
return $this->headers[$key] ?? null;
|
|
}
|
|
}
|