Initial commit of LightMVC framework files.
This commit is contained in:
Executable
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Core;
|
||||
|
||||
class Request
|
||||
{
|
||||
public function getPath()
|
||||
{
|
||||
$path = $_SERVER['REQUEST_URI'] ?? '/';
|
||||
$position = strpos($path, '?');
|
||||
if ($position === false) {
|
||||
return $path;
|
||||
}
|
||||
return substr($path, 0, $position);
|
||||
}
|
||||
|
||||
public function getMethod()
|
||||
{
|
||||
return strtolower($_SERVER['REQUEST_METHOD']);
|
||||
}
|
||||
|
||||
public function getBody()
|
||||
{
|
||||
$body = [];
|
||||
if ($this->getMethod() === 'get') {
|
||||
foreach ($_GET as $key => $value) {
|
||||
$body[$key] = filter_input(INPUT_GET, $key, FILTER_SANITIZE_SPECIAL_CHARS);
|
||||
}
|
||||
}
|
||||
if ($this->getMethod() === '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