diff --git a/src/Pecee/Http/Input/InputHandler.php b/src/Pecee/Http/Input/InputHandler.php index b40f917..e485505 100644 --- a/src/Pecee/Http/Input/InputHandler.php +++ b/src/Pecee/Http/Input/InputHandler.php @@ -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; + } + } \ No newline at end of file diff --git a/src/Pecee/Http/Input/InputItem.php b/src/Pecee/Http/Input/InputItem.php index bd8667e..19ed96d 100644 --- a/src/Pecee/Http/Input/InputItem.php +++ b/src/Pecee/Http/Input/InputItem.php @@ -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()); } diff --git a/src/Pecee/SimpleRouter/ClassLoader/ClassLoader.php b/src/Pecee/SimpleRouter/ClassLoader/ClassLoader.php index c73c7a8..c928339 100644 --- a/src/Pecee/SimpleRouter/ClassLoader/ClassLoader.php +++ b/src/Pecee/SimpleRouter/ClassLoader/ClassLoader.php @@ -48,7 +48,7 @@ class ClassLoader implements IClassLoader /** * Load closure * - * @param \Closure $closure + * @param Callable $closure * @param array $parameters * @return mixed * @throws NotFoundHttpException diff --git a/src/Pecee/SimpleRouter/Route/Route.php b/src/Pecee/SimpleRouter/Route/Route.php index 516a03f..54858a1 100644 --- a/src/Pecee/SimpleRouter/Route/Route.php +++ b/src/Pecee/SimpleRouter/Route/Route.php @@ -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; diff --git a/tests/Pecee/SimpleRouter/RouterRouteTest.php b/tests/Pecee/SimpleRouter/RouterRouteTest.php index a7bce6c..e92bd37 100644 --- a/tests/Pecee/SimpleRouter/RouterRouteTest.php +++ b/tests/Pecee/SimpleRouter/RouterRouteTest.php @@ -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'); });