Dependencies
This commit is contained in:
27
aldarien/response/app/Contract/Response.php
Normal file
27
aldarien/response/app/Contract/Response.php
Normal 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);
|
||||
}
|
||||
}
|
||||
?>
|
11
aldarien/response/app/Helper/functions.php
Normal file
11
aldarien/response/app/Helper/functions.php
Normal 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);
|
||||
}
|
||||
?>
|
62
aldarien/response/app/Service/Response.php
Normal file
62
aldarien/response/app/Service/Response.php
Normal 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;
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user