Development

- Updated `helpers.php` and helpers example in documentation.
- MalformedUrlException is now handled properly by Router to avoid phpStorm syntax highlights in routes.
- Added `getUrlCopy` to `Request` class, used to clone the current route (to keep domain etc.)
- `setUrl` in `Request` are now strict and requires `Url` object and no longer accepts strings.
- Renamed `hasRewrite` property to `hasPendingRewrite` in `Request` class.
- Renamed `hasRewrite` and `setHasRewrite` methods to `hasPendingRewrite` and `setHasPendingRewrite` in `Request` class.
- Added better usage of `Url` class. When calling `url` you can now use the methods on the `Url` class to filter params, get relative/absolute url etc. See documentation for more info.
- Renamed `get` method to `getValue` in `InputHandler` class.
- Renamed `getObject` to `get` and removed `$defaultValue` argument in `InputHandler` class.
- Optimized `InputHandler` class.
- Fixed issue with `$token` not being proper string in `BaseCsrfVerifier` when token is not found.
- Added php.ini configuration settings to `setcookie` in `CookieTokenProvider` for improved security.
- Added `$router` parameter to `boot` method in `IRouterBootManager` which allows for further manipulation of the router within the bootmanager.
- Renamed `$processingRoute` property to `$isProcessingRoute` in `Router` class.
- Fixed `reset` method not resetting CSRF-verifier in `Router` class.
- Moved `arrayToParams` helper-method from `Router` to `Url` class.
- Began to add Event-functionality to router.
- Added `addEventHandler` method to `SimpleRouter` class.
- Moved `Pecee\SimpleRouter\Handler\CallbackExceptionHandler` to `Pecee\SimpleRouter\Handlers\CallbackExceptionHandler`.
- Moved `Pecee\SimpleRouter\Handler\IExceptionHandler` to `Pecee\SimpleRouter\Handlers\IExceptionHandler`.
- Added Events section to documentation.
- Added more information on url-handling in documentation.
- Optimisations.
This commit is contained in:
Simon Sessingø
2018-03-29 18:17:42 +02:00
parent aa56d45f9c
commit a9c03f9271
35 changed files with 1528 additions and 489 deletions
+20 -21
View File
@@ -87,7 +87,6 @@ class InputHandler
}
$keys = [$key];
$files = $this->rearrangeFiles($value['name'], $keys, $value);
if (isset($list[$key]) === true) {
@@ -212,31 +211,26 @@ class InputHandler
* Get input object
*
* @param string $index
* @param string|null $defaultValue
* @param array|string|null $methods
* @return IInputItem|string
* @param array ...$methods
* @return IInputItem|null
*/
public function getObject(string $index, ?string $defaultValue = null, $methods = null)
public function get(string $index, ...$methods) : ?IInputItem
{
if ($methods !== null && \is_string($methods) === true) {
$methods = [$methods];
}
$element = null;
if ($methods === null || \in_array('get', $methods, true) === true) {
if (\count($methods) === 0 || \in_array('get', $methods, true) === true) {
$element = $this->findGet($index);
}
if (($element === null && $methods === null) || ($methods !== null && \in_array('post', $methods, true) === true)) {
if (($element === null && \count($methods) === 0) || (\count($methods) === 0 && \in_array('post', $methods, true) === true)) {
$element = $this->findPost($index);
}
if (($element === null && $methods === null) || ($methods !== null && \in_array('file', $methods, true) === true)) {
if (($element === null && \count($methods) === 0) || (\count($methods) === 0 && \in_array('file', $methods, true) === true)) {
$element = $this->findFile($index);
}
return $element ?? $defaultValue;
return $element;
}
/**
@@ -244,14 +238,14 @@ class InputHandler
*
* @param string $index
* @param string|null $defaultValue
* @param array|string|null $methods
* @return InputItem|string
* @param array ...$methods
* @return string
*/
public function get(string $index, ?string $defaultValue = null, $methods = null)
public function getValue(string $index, ?string $defaultValue = null, ...$methods) : ?string
{
$input = $this->getObject($index, $defaultValue, $methods);
$input = $this->get($index, $methods);
if ($input instanceof InputItem) {
if ($input !== null) {
return (trim($input->getValue()) === '') ? $defaultValue : $input->getValue();
}
@@ -262,11 +256,12 @@ class InputHandler
* Check if a input-item exist
*
* @param string $index
* @param array ...$method
* @return bool
*/
public function exists(string $index): bool
public function exists(string $index, ...$method): bool
{
return ($this->getObject($index) !== null);
return $this->get($index, $method) !== null;
}
/**
@@ -276,12 +271,16 @@ class InputHandler
*/
public function all(array $filter = null): array
{
$output = $_GET + $_POST;
$output = $_GET;
if ($this->request->getMethod() === 'post') {
// Append POST data
$output += $_POST;
$contents = file_get_contents('php://input');
// Append any PHP-input json
if (strpos(trim($contents), '{') === 0) {
$post = json_decode($contents, true);
if ($post !== false) {