Merge pull request #98 from skipperbent/development

Development
This commit is contained in:
Simon Sessingø
2016-04-22 14:30:40 +02:00
3 changed files with 29 additions and 22 deletions
+8 -14
View File
@@ -49,12 +49,13 @@ class Input {
} }
public function getObject($index, $default = null) { 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; $index = (strpos($index, '[') > -1) ? substr($index, 0, strpos($index, '[')) : $index;
$element = $this->get->findFirst($index); $element = $this->get->findFirst($index);
if($element !== null) { if($element !== null) {
return $element; return ($key !== null) ? $element[$key] : $element;
} }
if(Request::getInstance()->getMethod() !== 'get') { if(Request::getInstance()->getMethod() !== 'get') {
@@ -62,12 +63,12 @@ class Input {
$element = $this->post->findFirst($index); $element = $this->post->findFirst($index);
if ($element !== null) { if ($element !== null) {
return $element; return ($key !== null) ? $element[$key] : $element;
} }
$element = $this->file->findFirst($index); $element = $this->file->findFirst($index);
if ($element !== null) { if ($element !== null) {
return $element; return ($key !== null) ? $element[$key] : $element;
} }
} }
@@ -82,21 +83,14 @@ class Input {
*/ */
public function get($index, $default = null) { 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); $item = $this->getObject($index);
if($item !== null) { if($item !== null) {
if($item instanceof InputFile) { if(is_array($item) || $item instanceof InputFile) {
return $item; 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(); return (trim($item->getValue()) === '') ? $default : $item->getValue();
} }
@@ -119,7 +113,7 @@ class Input {
$output[$k] = new InputItem($k, $g); $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); $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;
} }
} }
} }
+10 -7
View File
@@ -303,13 +303,17 @@ class RouterBase {
} }
public function arrayToParams(array $getParams = null, $includeEmpty = true) { public function arrayToParams(array $getParams = null, $includeEmpty = true) {
if (is_array($getParams) && count($getParams) > 0) {
foreach ($getParams as $key => $val) { if(is_array($getParams)) {
if (!empty($val) || $includeEmpty) { if ($includeEmpty === false) {
$getParams[$key] = (is_array($val) ? $this->arrayToParams($val, $includeEmpty) : $key . '=' . $val); $getParams = array_filter($getParams, function ($item) {
if (!empty($item)) {
return $item;
} }
});
} }
return join('&', $getParams);
return http_build_query($getParams);
} }
return ''; return '';
} }
@@ -386,8 +390,7 @@ class RouterBase {
if($controller === null && $parameters === null) { if($controller === null && $parameters === null) {
$getParams = (is_array($getParams)) ? array_merge($_GET, $getParams) : $_GET; $getParams = (is_array($getParams)) ? array_merge($_GET, $getParams) : $_GET;
$url = parse_url(Request::getInstance()->getUri()); $url = parse_url($this->request->getUri(), PHP_URL_PATH);
$url = $url['path'];
if(count($getParams)) { if(count($getParams)) {
$url .= '?' . $this->arrayToParams($getParams); $url .= '?' . $this->arrayToParams($getParams);
+10
View File
@@ -98,4 +98,14 @@ class RouterGroup extends RouterEntry {
return $this; return $this;
} }
public function getMergeableSettings() {
$settings = parent::getMergeableSettings();
if(isset($settings['middleware'])) {
unset($settings['middleware']);
}
return $settings;
}
} }