. * */ namespace Vvveb\System\Core; class Request { public $get = []; public $post = []; public $request = []; public $cookie = []; public $files = []; public $server = []; private $method; protected static $instance; public static function getInstance() { if (is_null(static::$instance)) { static::$instance = new static(); } return static::$instance; } final private function __construct() { $this->get = &$_GET; $this->post = &$_POST; $this->request = &$_REQUEST; $this->cookie = &$_COOKIE; $this->files = &$_FILES; $this->server = &$_SERVER; $this->post = $this->filter($this->post, false); $this->get = $this->filter($this->get); $this->request = $this->filter($this->request); $this->cookie = $this->filter($this->cookie); $this->files = $this->filter($this->files); $this->method = strtolower($_SERVER['REQUEST_METHOD'] ?? 'get'); if ($this->method == 'put' || $this->method == 'patch') { parse_str(file_get_contents('php://input'), $post); $this->post = $this->filter($post, false); } $this->request = array_merge($this->request, $this->get, $this->post); } public function filter($data, $filterText = true) { if (is_array($data)) { foreach ($data as $key => $value) { unset($data[$key]); $key = substr($this->filter($key, $filterText), 0, 255); $data[$key] = $this->filter($value, $filterText); } } else { if ($filterText) { $data = \Vvveb\filterText($data); } else { //$data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8'); $data = $data; } } return $data; } public function getMethod() { return $this->method; } public function isAjax() { return isset($this->server['HTTP_X_REQUESTED_WITH']) && $this->server['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; } }