This commit is contained in:
Juan Pablo Vial
2023-07-24 20:41:38 -04:00
parent 6ab24c8961
commit be33305cf1
612 changed files with 11436 additions and 107 deletions

View File

@ -0,0 +1,27 @@
<?php
namespace App\Contract;
use App\Definition\Contract;
use App\Service\Response as ResponseService;
class Response
{
use Contract;
protected static function newInstance()
{
return new ResponseService();
}
public static function __callStatic($name, $params)
{
if (!method_exists(Response::class, $name)) {
$instance = self::getInstance();
if (method_exists($instance, $name)) {
return call_user_func_array([$instance, $name], $params);
}
return null;
}
return call_user_func_array([self, $name], $params);
}
}
?>

View File

@ -0,0 +1,11 @@
<?php
function sanitize() {
App\Contract\Response::sanitize();
}
function get($query = null) {
return App\Contract\Response::get($query);
}
function post($query = null) {
return App\Contract\Response::post($query);
}
?>

View File

@ -0,0 +1,62 @@
<?php
namespace App\Service;
class Response
{
protected $post;
protected $get;
protected $gump;
public function __construct()
{
$this->gump = new \GUMP();
}
public function sanitize()
{
if ($_POST) {
$this->post = $this->correctNumbers($this->gump->sanitize($_POST));
}
if ($_GET) {
$this->get = $this->correctNumbers($this->gump->sanitize($_GET));
}
}
public function correctNumbers(array $data)
{
$output = [];
foreach ($data as $key => $value) {
if (is_float(str_replace(',', '.', $value))) {
$output[$key] = str_replace(',', '.', $value);
} else {
$output[$key] = $value;
}
}
return $output;
}
public function get($query = null)
{
if ($this->get == null) {
$this->sanitize();
}
if ($query == null) {
return $this->get;
}
if (isset($this->get[$query])) {
return $this->get[$query];
}
return false;
}
public function post($query = null)
{
if ($this->post == null) {
$this->sanitize();
}
if ($query == null) {
return $this->post;
}
if (isset($this->post[$query])) {
return $this->post[$query];
}
return false;
}
}
?>