Dependencies
This commit is contained in:
7
aldarien/response/.gitignore
vendored
Normal file
7
aldarien/response/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
#Eclipse IDE
|
||||
.settings
|
||||
.buildpath
|
||||
.project
|
||||
|
||||
#Composer
|
||||
vendor
|
21
aldarien/response/LICENSE
Normal file
21
aldarien/response/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Aldarien
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
2
aldarien/response/README.md
Normal file
2
aldarien/response/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
# response
|
||||
Response handler module for my apps
|
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;
|
||||
}
|
||||
}
|
||||
?>
|
3
aldarien/response/bootstrap/autoload.php
Normal file
3
aldarien/response/bootstrap/autoload.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
include_once dirname(__DIR__) . '/vendor/autoload.php';
|
||||
?>
|
26
aldarien/response/composer.json
Normal file
26
aldarien/response/composer.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"name" : "aldarien/response",
|
||||
"description" : "Response handler module for my apps",
|
||||
"type" : "library",
|
||||
"require" : {
|
||||
"wixel/gump" : "^1.5",
|
||||
"aldarien/contract" : "dev-master"
|
||||
},
|
||||
"require-dev" : {
|
||||
"phpunit/phpunit" : "^6.3"
|
||||
},
|
||||
"license" : "MIT",
|
||||
"authors" : [{
|
||||
"name" : "Aldarien",
|
||||
"email" : "jpvial@gmail.com"
|
||||
}
|
||||
],
|
||||
"autoload" : {
|
||||
"psr-4" : {
|
||||
"App\\" : "app"
|
||||
},
|
||||
"files": [
|
||||
"app/Helper/functions.php"
|
||||
]
|
||||
}
|
||||
}
|
17
aldarien/response/phpunit.xml
Normal file
17
aldarien/response/phpunit.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit
|
||||
colors="true"
|
||||
verbose="true"
|
||||
bootstrap="./bootstrap/autoload.php"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Application Test Suite">
|
||||
<directory>./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./app</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
22
aldarien/response/tests/ResponseTest.php
Normal file
22
aldarien/response/tests/ResponseTest.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ResponseTest extends TestCase
|
||||
{
|
||||
protected $value = 'Test';
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$_GET['test'] = $this->value;
|
||||
$_POST['test'] = $this->value;
|
||||
}
|
||||
public function testGet()
|
||||
{
|
||||
$this->assertEquals($this->value, get('test'));
|
||||
}
|
||||
public function testPost()
|
||||
{
|
||||
$this->assertEquals($this->value, post('test'));
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user