facut pana la video 7

This commit is contained in:
Cerbu Andrei Mihnea
2023-05-10 00:47:48 +03:00
parent 1abdc313f4
commit 90f12ab916
40 changed files with 1644 additions and 41 deletions
+54
View File
@@ -0,0 +1,54 @@
<?php
namespace app\core;
class Request{
private int $lengthOfRoot;
public function __construct(){
$this->lengthOfRoot = strlen('knowyourfood') + 1;
}
public function getPath(){//identificam din URL pe pagina trebuie accesata
$path = $_SERVER['REQUEST_URI'];
$path = substr($path, $this->lengthOfRoot);
$position = strpos($path, '?');
if(!$position){
return $path;
}
return substr($path, 0, $position);
}
public function method(){
return strtolower($_SERVER['REQUEST_METHOD']);
}
public function isGet(){
return $this->method() === 'get';
}
public function isPost(){
return $this->method() === 'post';
}
//bazat pe tipul de request, accesam tuplele key/value pentru a identifica body ul requestului
public function getBody(){
$body = [];
if($this->method() === 'get'){
foreach($_GET as $key => $value){
$body[$key] = filter_input(INPUT_GET, $key, FILTER_SANITIZE_SPECIAL_CHARS);
}
}
if($this->method() === 'post'){
foreach($_POST as $key => $value){
$body[$key] = filter_input(INPUT_POST, $key, FILTER_SANITIZE_SPECIAL_CHARS);
}
}
return $body;
}
}