InputHandler optimisations.

- InputItem can now be used like array (for example: input()->get('items')[0]) if value is array.
- Changed default-value parameter for get, post, file can now be mixed to allow object as return-type.
This commit is contained in:
Simon Sessingø
2021-05-18 18:00:18 +02:00
parent df9a855579
commit 0d6326dfbb
2 changed files with 33 additions and 7 deletions
+27 -1
View File
@@ -2,10 +2,11 @@
namespace Pecee\Http\Input;
use ArrayAccess;
use ArrayIterator;
use IteratorAggregate;
class InputItem implements IInputItem, IteratorAggregate
class InputItem implements ArrayAccess, IInputItem, IteratorAggregate
{
public $index;
public $name;
@@ -75,9 +76,34 @@ class InputItem implements IInputItem, IteratorAggregate
return $this;
}
public function offsetExists($offset): bool
{
return isset($this->value[$offset]);
}
public function offsetGet($offset)
{
if ($this->offsetExists($offset) === true) {
return $this->value[$offset];
}
return null;
}
public function offsetSet($offset, $value): void
{
$this->value[$offset] = $value;
}
public function offsetUnset($offset): void
{
unset($this->data[$offset]);
}
public function __toString(): string
{
$value = $this->getValue();
return (is_array($value) === true) ? json_encode($value) : $value;
}