54 lines
1.1 KiB
PHP
Executable File
54 lines
1.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\core;
|
|
|
|
class Request{
|
|
public function __construct(){
|
|
}
|
|
|
|
public function getPath(): string
|
|
{
|
|
return $_SERVER['REQUEST_URI'];
|
|
}
|
|
|
|
public function method():string
|
|
{
|
|
return $_SERVER['REQUEST_METHOD'];
|
|
}
|
|
|
|
public function isGet(): bool
|
|
{
|
|
return $_SERVER['REQUEST_METHOD'] === "GET";
|
|
}
|
|
|
|
public function isPost(): bool
|
|
{
|
|
return $_SERVER['REQUEST_METHOD'] === "POST";
|
|
}
|
|
|
|
public function getGETBody(): ?array
|
|
{
|
|
$body = [];
|
|
|
|
if($this->method() === 'GET'){
|
|
foreach($_GET as $key => $value){
|
|
$body[$key] = filter_input(INPUT_GET, $key, FILTER_SANITIZE_SPECIAL_CHARS);
|
|
}
|
|
}
|
|
|
|
return $body;
|
|
}
|
|
|
|
public function getPOSTBody(): ?array
|
|
{
|
|
$body = [];
|
|
|
|
if($this->method() === 'POST'){
|
|
foreach($_POST as $key => $value){
|
|
$body[$key] = filter_input(INPUT_POST, $key, FILTER_SANITIZE_SPECIAL_CHARS);
|
|
}
|
|
}
|
|
|
|
return $body;
|
|
}
|
|
} |