- Optimized Input class.

- Input class now returns array instead of InputItem instance when object is of type array.
- Optimized key behavior in Input class.
- Optimized arrayToParams method in RouterBase class.
- Added getMergableSettings method to RouterGroup to avoid middleware merge; as they will already be loaded.
This commit is contained in:
Simon Sessingø
2016-04-22 12:55:24 +02:00
parent 1420203149
commit 67a00c6800
3 changed files with 28 additions and 21 deletions
+7 -13
View File
@@ -49,12 +49,13 @@ class Input {
}
public function getObject($index, $default = null) {
$key = (strpos($index, '[') > -1) ? substr($index, strpos($index, '[')+1, strpos($index, ']') - strlen($index)) : null;
$index = (strpos($index, '[') > -1) ? substr($index, 0, strpos($index, '[')) : $index;
$element = $this->get->findFirst($index);
if($element !== null) {
return $element;
return ($key !== null) ? $element[$key] : $element;
}
if(Request::getInstance()->getMethod() !== 'get') {
@@ -62,12 +63,12 @@ class Input {
$element = $this->post->findFirst($index);
if ($element !== null) {
return $element;
return ($key !== null) ? $element[$key] : $element;
}
$element = $this->file->findFirst($index);
if ($element !== null) {
return $element;
return ($key !== null) ? $element[$key] : $element;
}
}
@@ -82,9 +83,6 @@ class Input {
*/
public function get($index, $default = null) {
$key = (strpos($index, '[') > -1) ? substr($index, strpos($index, '[')+1, strpos($index, ']') - strlen($index)) : null;
$index = (strpos($index, '[') > -1) ? substr($index, 0, strpos($index, '[')) : $index;
$item = $this->getObject($index);
if($item !== null) {
@@ -93,10 +91,6 @@ class Input {
return $item;
}
if (is_array($item->getValue())) {
return ($key !== null && isset($item->getValue()[$key])) ? $item->getValue()[$key] : $item->getValue();
}
return (trim($item->getValue()) === '') ? $default : $item->getValue();
}
@@ -119,7 +113,7 @@ class Input {
$output[$k] = new InputItem($k, $g);
}
$this->get->{$key} = new InputItem($key, $output);
$this->get->{$key} = $output;
}
}
}
@@ -149,7 +143,7 @@ class Input {
$output[$k] = new InputItem($k, $p);
}
$this->post->{strtolower($key)} = new InputItem($key, $output);
$this->post->{strtolower($key)} = $output;
}
}
}
@@ -189,7 +183,7 @@ class Input {
}
}
$this->file->{strtolower($key)} = new InputItem($key, $output);
$this->file->{strtolower($key)} = $output;
}
}
}