facut pana la video 7
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user