Skip to content
This repository was archived by the owner on Aug 13, 2023. It is now read-only.

Commit

Permalink
add between
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Feb 15, 2017
1 parent ab767ae commit 22d4a3c
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 24 deletions.
11 changes: 1 addition & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@ php:
- nightly

before_script:
- "composer require codeclimate/php-test-reporter --dev"
- "composer install"

script:
- "phpunit --coverage-text --coverage-clover build/logs/clover.xml"

after_script:
- CODECLIMATE_REPO_TOKEN="a463f7246ccf358b66f81f9ea0c75e39cc76161050f57dea3acbc86c039f5c3c" vendor/bin/test-reporter --stdout > codeclimate.json
- "sh -c 'if [ \"$TRAVIS_PHP_VERSION\" != \"hhvm\" ]; then curl -X POST -d @codeclimate.json -H \"Content-Type: application/json\" -H \"User-Agent: Code Climate (PHP Test Reporter v0.1.1)\" https://codeclimate.com/test_reports ; fi'"

addons:
code_climate:
repo_token: a463f7246ccf358b66f81f9ea0c75e39cc76161050f57dea3acbc86c039f5c3c
- "phpunit --coverage-text --coverage-clover build/logs/clover.xml"
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
},
"require-dev": {
"deimos/router": "~0.0",
"phpunit/phpunit": "5.7.5",
"codeclimate/php-test-reporter": "dev-master"
"phpunit/phpunit": "5.7.5"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions demo/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'deimos' => [
'type' => 'pattern',
'path' => '/deimos/?',
'path' => '/deimos',

'defaults' => [
'controller' => 'deimos',
Expand All @@ -20,7 +20,7 @@

'default' => [
'type' => 'pattern',
'path' => '/(<controller>/(<action>/(<id:\d+>)))/?',
'path' => '/(<controller>/(<action>/(<id:\d+>)))',

'defaults' => [
'controller' => 'cms',
Expand Down
2 changes: 2 additions & 0 deletions src/Request/Adapter/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @method string dataIP(string $path = null, mixed $default = '', bool $strip = true)
* @method string dataURL(string $path = null, mixed $default = '', bool $strip = true)
* @method mixed dataUnsafe(string $path = null, mixed $default = '')
* @method double dataBetween(string $path = null, double $min, double $max)
*
* @method int postInt(string $path = null, mixed $default = 0, bool $strip = true)
* @method float postFloat(string $path = null, mixed $default = 0.0, bool $strip = true)
Expand All @@ -22,6 +23,7 @@
* @method string postIP(string $path = null, mixed $default = '', bool $strip = true)
* @method string postURL(string $path = null, mixed $default = '', bool $strip = true)
* @method mixed postUnsafe(string $path = null, mixed $default = '')
* @method double postBetween(string $path = null, double $min, double $max)
*/
trait Data
{
Expand Down
5 changes: 4 additions & 1 deletion src/Request/Adapter/Other.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
* @method string putIP(string $path = null, mixed $default = '', bool $strip = true)
* @method string putURL(string $path = null, mixed $default = '', bool $strip = true)
* @method mixed putUnsafe(string $path = null, mixed $default = '')
* @method double putBetween(string $path = null, double $min, double $max)
*
* @method int patchInt(string $path = null, mixed $default = 0, bool $strip = true)
* @method float patchFloat(string $path = null, mixed $default = 0.0, bool $strip = true)
* @method bool patchBool(string $path = null, mixed $default = false, bool $strip = true)
* @method string patchEmail(string $path = null, mixed $default = '', bool $strip = true)
* @method string patchIP(string $path = null, mixed $default = '', bool $strip = true)
* @method string patchURL(string $path = null, mixed $default = '', bool $strip = true)
* @method mixed pathUnsafe(string $path = null, mixed $default = '')
* @method mixed patchUnsafe(string $path = null, mixed $default = '')
* @method double patchBetween(string $path = null, double $min, double $max)
*
* @method int deleteInt(string $path = null, mixed $default = 0, bool $strip = true)
* @method float deleteFloat(string $path = null, mixed $default = 0.0, bool $strip = true)
Expand All @@ -30,6 +32,7 @@
* @method string deleteIP(string $path = null, mixed $default = '', bool $strip = true)
* @method string deleteURL(string $path = null, mixed $default = '', bool $strip = true)
* @method mixed deleteUnsafe(string $path = null, mixed $default = '')
* @method double deleteBetween(string $path = null, double $min, double $max)
*/
trait Other
{
Expand Down
2 changes: 2 additions & 0 deletions src/Request/Adapter/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @method string queryIP(string $path = null, mixed $default = '', bool $strip = true)
* @method string queryURL(string $path = null, mixed $default = '', bool $strip = true)
* @method mixed queryUnsafe(string $path = null, mixed $default = '')
* @method double queryBetween(string $path = null, double $min, double $max)
*
* @method int getInt(string $path = null, mixed $default = 0, bool $strip = true)
* @method float getFloat(string $path = null, mixed $default = 0.0, bool $strip = true)
Expand All @@ -22,6 +23,7 @@
* @method string getIP(string $path = null, mixed $default = '', bool $strip = true)
* @method string getURL(string $path = null, mixed $default = '', bool $strip = true)
* @method mixed getUnsafe(string $path = null, mixed $default = '')
* @method double getBetween(string $path = null, double $min, double $max)
*/
trait Query
{
Expand Down
1 change: 1 addition & 0 deletions src/Request/Adapter/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @method string requestIP(string $path = null, mixed $default = '', bool $strip = true)
* @method string requestURL(string $path = null, mixed $default = '', bool $strip = true)
* @method mixed requestUnsafe(string $path = null, mixed $default = '')
* @method double requestBetween(string $path = null, double $min, double $max)
*/
trait Request
{
Expand Down
1 change: 1 addition & 0 deletions src/Request/Adapter/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* @method string attributeIP(string $path = null, mixed $default = '')
* @method string attributeURL(string $path = null, mixed $default = '')
* @method mixed attributeUnsafe(string $path = null, mixed $default = '')
* @method double attributeBetween(string $path = null, double $min, double $max)
*/
trait Router
{
Expand Down
51 changes: 42 additions & 9 deletions src/Request/AdapterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trait AdapterExtension
'bool' => FILTER_VALIDATE_BOOLEAN,
'email' => FILTER_VALIDATE_EMAIL,
'ip' => FILTER_VALIDATE_IP,
'url' => FILTER_VALIDATE_URL,
'url' => FILTER_VALIDATE_URL
];

/**
Expand Down Expand Up @@ -71,6 +71,34 @@ private function unsafeFilter($call, $arguments)
return call_user_func_array([$this, $call], $arguments);
}

/**
* @param $call
* @param $arguments
*
* @return mixed
*/
private function betweenFilter($call, $arguments)
{
$num = $this->unsafeFilter($call, $arguments);

if (is_numeric($num))
{
if ($arguments[2] <= $num)
{
return $arguments[2];
}

if ($arguments[1] >= $num)
{
return $arguments[1];
}

return $num;
}

return null;
}

/**
* @param $name
*
Expand Down Expand Up @@ -98,16 +126,21 @@ public function __call($name, $arguments)

$this->allowMethods($call, $name);

if ($filter === 'unsafe')
switch ($filter)
{
return $this->unsafeFilter($call, $arguments);
case 'unsafe':
return $this->unsafeFilter($call, $arguments);

case 'between':
return $this->betweenFilter($call, $arguments);

default:
return $this->filterVariable(
call_user_func_array([$this, $call], $arguments),
$this->filters[$filter],
$this->defaults[$filter]
);
}

return $this->filterVariable(
call_user_func_array([$this, $call], $arguments),
$this->filters[$filter],
$this->defaults[$filter]
);
}

}
8 changes: 8 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@
$loader = require dirname(__DIR__) . '/vendor/autoload.php';

$loader->addPsr4('DeimosTest\\', 'tests/src/');

if (class_exists('PHPUnit\\Framework\\TestCase'))
{
class PHPUnit_Framework_TestCase extends \PHPUnit\Framework\TestCase
{

}
}

0 comments on commit 22d4a3c

Please sign in to comment.