microserviciile de register, login finalizate
This commit is contained in:
Executable
+43
@@ -0,0 +1,43 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user