Files

43 lines
1.1 KiB
PHP
Executable File

<?php
namespace app\core;
class Request{
public function getPath(): string
{
return $_SERVER['REQUEST_URI'];
}
public function method(): string
{
return $_SERVER['REQUEST_METHOD'];
}
public function getToken(): ?string
{
return array_key_exists("Authorization",apache_request_headers()) ?
apache_request_headers()["Authorization"] : NULL;
}
public function getAuthRequest(): string
{
return array_key_exists("Auth-Request", apache_request_headers()) ?
apache_request_headers()["Auth-Request"] : "default";
}
public function getBody(): ?array
{
if(!array_key_exists("Content-Length", apache_request_headers())) return NULL;
$bytesToRead = intval(apache_request_headers()["Content-Length"]);
if($bytesToRead == 0) return NULL;
$inputStream = fopen('php://input', 'r');
$jsonData = fread($inputStream, $bytesToRead);
fclose($inputStream);
$jsonData = json_decode($jsonData, true);
return empty($jsonData) ? [] : $jsonData;
}
}