Development

- Removed unused class references.
- Removed escape from `-` in reg-ex as it's only required when next to character-class.
- Added `$_FILE` support for `all` method.
- Bugfixes.
This commit is contained in:
Simon Sessingø
2021-03-21 15:19:27 +01:00
parent 4639879a67
commit 8254c5b100
5 changed files with 74 additions and 17 deletions
+65 -5
View File
@@ -34,10 +34,10 @@ class InputHandler
protected $originalPost = [];
/**
* Original get variables
* Original get/params variables
* @var array
*/
protected $originalGet = [];
protected $originalParams = [];
/**
* Get original file variables
@@ -64,8 +64,8 @@ class InputHandler
{
/* Parse get requests */
if (\count($_GET) !== 0) {
$this->originalGet = $_GET;
$this->get = $this->parseInputItem($this->originalGet);
$this->originalParams = $_GET;
$this->get = $this->parseInputItem($this->originalParams);
}
/* Parse post requests */
@@ -318,7 +318,7 @@ class InputHandler
*/
public function all(array $filter = []): array
{
$output = $this->originalGet + $this->originalPost;
$output = $this->originalParams + $this->originalPost + $this->originalFile;
$output = (\count($filter) > 0) ? array_intersect_key($output, array_flip($filter)) : $output;
foreach ($filter as $filterKey) {
@@ -363,4 +363,64 @@ class InputHandler
$this->file[$key] = $item;
}
/**
* Get original post variables
* @return array
*/
public function getOriginalPost(): array
{
return $this->originalPost;
}
/**
* Set original post variables
* @param array $post
* @return static $this
*/
public function setOriginalPost(array $post): self
{
$this->originalPost = $post;
return $this;
}
/**
* Get original get variables
* @return array
*/
public function getOriginalParams(): array
{
return $this->originalParams;
}
/**
* Set original get-variables
* @param array $params
* @return static $this
*/
public function setOriginalParams(array $params): self
{
$this->originalParams = $params;
return $this;
}
/**
* Get original file variables
* @return array
*/
public function getOriginalFile(): array
{
return $this->originalFile;
}
/**
* Set original file posts variables
* @param array $file
* @return static $this
*/
public function setOriginalFile(array $file): self
{
$this->originalFile = $file;
return $this;
}
}
+1 -4
View File
@@ -2,9 +2,6 @@
namespace Pecee\Http\Input;
use Exception;
use Traversable;
class InputItem implements IInputItem, \IteratorAggregate
{
public $index;
@@ -81,7 +78,7 @@ class InputItem implements IInputItem, \IteratorAggregate
return (\is_array($value) === true) ? json_encode($value) : $value;
}
public function getIterator()
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->getValue());
}
@@ -48,7 +48,7 @@ class ClassLoader implements IClassLoader
/**
* Load closure
*
* @param \Closure $closure
* @param Callable $closure
* @param array $parameters
* @return mixed
* @throws NotFoundHttpException
+3 -3
View File
@@ -10,7 +10,7 @@ use Pecee\SimpleRouter\Router;
abstract class Route implements IRoute
{
protected const PARAMETERS_REGEX_FORMAT = '%s([\w]+)(\%s?)%s';
protected const PARAMETERS_DEFAULT_REGEX = '[\w\-]+';
protected const PARAMETERS_DEFAULT_REGEX = '[\w-]+';
/**
* If enabled parameters containing null-value
@@ -122,7 +122,7 @@ abstract class Route implements IRoute
$urlRegex = preg_quote($route, '/');
} else {
foreach (preg_split('/((\-?\/?){[^}]+})/', $route) as $key => $t) {
foreach (preg_split('/((-?\/?){[^}]+})/', $route) as $key => $t) {
$regex = '';
@@ -137,7 +137,7 @@ abstract class Route implements IRoute
$regex = $parameterRegex ?? $this->defaultParameterRegex ?? static::PARAMETERS_DEFAULT_REGEX;
}
$regex = sprintf('((\/|\-)(?P<%2$s>%3$s))%1$s', $parameters[2][$key], $name, $regex);
$regex = sprintf('((\/|-)(?P<%2$s>%3$s))%1$s', $parameters[2][$key], $name, $regex);
}
$urlRegex .= preg_quote($t, '/') . $regex;
+4 -4
View File
@@ -101,7 +101,7 @@ class RouterRouteTest extends \PHPUnit\Framework\TestCase
public function testPathParamRegex()
{
TestRouter::get('/{lang}/productscategories/{name}', 'DummyController@param', ['where' => ['lang' => '[a-z]+', 'name' => '[A-Za-z0-9\-]+']]);
TestRouter::get('/{lang}/productscategories/{name}', 'DummyController@param', ['where' => ['lang' => '[a-z]+', 'name' => '[A-Za-z0-9-]+']]);
$response = TestRouter::debugOutput('/it/productscategories/system', 'get');
$this->assertEquals('it, system', $response);
@@ -144,7 +144,7 @@ class RouterRouteTest extends \PHPUnit\Framework\TestCase
public function testRegEx()
{
TestRouter::get('/my/{path}', 'DummyController@method1')->where(['path' => '[a-zA-Z\-]+']);
TestRouter::get('/my/{path}', 'DummyController@method1')->where(['path' => '[a-zA-Z-]+']);
TestRouter::debug('/my/custom-path', 'get');
$this->assertTrue(true);
@@ -182,7 +182,7 @@ class RouterRouteTest extends \PHPUnit\Framework\TestCase
public function testDefaultParameterRegex()
{
TestRouter::get('/my/{path}', 'DummyController@param', ['defaultParameterRegex' => '[\w\-]+']);
TestRouter::get('/my/{path}', 'DummyController@param', ['defaultParameterRegex' => '[\w-]+']);
$output = TestRouter::debugOutput('/my/custom-regex', 'get');
$this->assertEquals('custom-regex', $output);
@@ -190,7 +190,7 @@ class RouterRouteTest extends \PHPUnit\Framework\TestCase
public function testDefaultParameterRegexGroup()
{
TestRouter::group(['defaultParameterRegex' => '[\w\-]+'], function () {
TestRouter::group(['defaultParameterRegex' => '[\w-]+'], function () {
TestRouter::get('/my/{path}', 'DummyController@param');
});