Compare commits

...

6 Commits

Author SHA1 Message Date
Simon Sessingø 30d2285699 Merge pull request #392 from skipperbent/v4-development
Bugfixes
2018-03-29 22:36:01 +02:00
Simon Sessingø a1dc4c5119 Bugfixes
- Updated `input` helper function.
- Update documentation to reflect v4 changes in `InputHandler` class.
2018-03-29 22:35:21 +02:00
Simon Sessingø 87e1fa3775 Merge pull request #391 from skipperbent/v4-development
Bugfixes
2018-03-29 22:18:26 +02:00
Simon Sessingø a11595fb86 Bugfixes
- Fixed `$methods` argument not properly passed in `InputHandler` class.
- Updated helpers.php with latest changes.
2018-03-29 22:17:53 +02:00
Simon Sessingø 555afd04f1 Merge pull request #390 from skipperbent/v4-development
Fixed defaultValue issue in `getValue` method in `InputHandler` class.
2018-03-29 21:45:26 +02:00
Simon Sessingø e6db83c97a Fixed defaultValue issue in getValue method in InputHandler class. 2018-03-29 21:44:41 +02:00
3 changed files with 21 additions and 38 deletions
+13 -20
View File
@@ -284,9 +284,9 @@ To implement the functions below, simply copy the code to a new file and require
<?php
use Pecee\SimpleRouter\SimpleRouter as Router;
use \Pecee\Http\Url;
use \Pecee\Http\Response;
use \Pecee\Http\Request;
use Pecee\Http\Url;
use Pecee\Http\Response;
use Pecee\Http\Request;
/**
* Get url for a route by using either name/alias, class or method name.
@@ -331,18 +331,13 @@ function request(): Request
* Get input class
* @param string|null $index Parameter index name
* @param string|null $defaultValue Default return value
* @param string|array|null $methods Default method
* @param array ...$methods Default methods
* @return \Pecee\Http\Input\InputHandler|\Pecee\Http\Input\IInputItem|string
*/
function input($index = null, $defaultValue = null, $methods = null)
function input($index = null, $defaultValue = null, ...$methods)
{
if ($index !== null) {
if ($defaultValue !== null) {
return request()->getInputHandler()->getValue($index, $defaultValue, $methods);
}
return request()->getInputHandler()->get($index, $methods);
return request()->getInputHandler()->getValue($index, $defaultValue, ...$methods);
}
return request()->getInputHandler();
@@ -1177,18 +1172,16 @@ $value = input($index, $defaultValue, $methods);
### Get parameter object
Will return an instance of `InputItem` or `InputFile` depending on the type.
The example below will return an instance of `InputItem` or `InputFile` depending on the type.
You can use this in your html as it will render the value of the item.
However if you want to compare value in your if statements, you have to use
the `getValue` or use the `input()` instead.
If you want to compare value in your if statements, you have to use the `getValue` or use the `input()` helper function instead.
If items is grouped in the html, it will return an array of items.
**Note:** `getObject` will only return `$defaultValue` if the item doesn't exist. If you want `$defaultValue` to be returned if the item is empty, please use `input()` instead.
```php
$object = input()->getObject($index, $defaultValue = null, $methods = null);
$object = input()->get($index, $defaultValue = null, $methods = null);
```
### Return specific GET parameter (where name is the name of your parameter):
@@ -1210,9 +1203,9 @@ $id = input($index, $defaultValue, $method);
# -- match specific --
$object = input($index, $defaultValue, 'get');
$object = input($index, $defaultValue, 'post');
$object = input($index, $defaultValue, 'file');
$value = input($index, $defaultValue, 'get');
$value = input($index, $defaultValue, 'post');
$value = input($index, $defaultValue, 'file');
# -- or --
+6 -11
View File
@@ -1,9 +1,9 @@
<?php
use Pecee\SimpleRouter\SimpleRouter as Router;
use \Pecee\Http\Url;
use \Pecee\Http\Response;
use \Pecee\Http\Request;
use Pecee\Http\Url;
use Pecee\Http\Response;
use Pecee\Http\Request;
/**
* Get url for a route by using either name/alias, class or method name.
@@ -48,18 +48,13 @@ function request(): Request
* Get input class
* @param string|null $index Parameter index name
* @param string|null $defaultValue Default return value
* @param string|array|null $methods Default method
* @param array ...$methods Default methods
* @return \Pecee\Http\Input\InputHandler|\Pecee\Http\Input\IInputItem|string
*/
function input($index = null, $defaultValue = null, $methods = null)
function input($index = null, $defaultValue = null, ...$methods)
{
if ($index !== null) {
if ($defaultValue !== null) {
return request()->getInputHandler()->getValue($index, $defaultValue, $methods);
}
return request()->getInputHandler()->get($index, $methods);
return request()->getInputHandler()->getValue($index, $defaultValue, ...$methods);
}
return request()->getInputHandler();
+2 -7
View File
@@ -243,13 +243,8 @@ class InputHandler
*/
public function getValue(string $index, ?string $defaultValue = null, ...$methods): ?string
{
$input = $this->get($index, $methods);
if ($input !== null) {
return (trim($input->getValue()) === '') ? $defaultValue : $input->getValue();
}
return $input;
$input = $this->get($index, ...$methods);
return ($input === null || ($input !== null && trim($input->getValue()) === '')) ? $defaultValue : $input->getValue();
}
/**