mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 08:47:52 +00:00
Optimisations and bugfixes
This commit is contained in:
@@ -301,28 +301,6 @@ class RouterBase {
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function httpBuildQuery(array $input) {
|
|
||||||
|
|
||||||
$output = '';
|
|
||||||
|
|
||||||
if(count($input)) {
|
|
||||||
|
|
||||||
$output .= '?';
|
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
foreach ($input as $key => $value) {
|
|
||||||
$output .= $key . '=' . urlencode($value);
|
|
||||||
if (($i + 1) < count($input)) {
|
|
||||||
$output .= '&';
|
|
||||||
}
|
|
||||||
$i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function arrayToParams(array $getParams = null, $includeEmpty = true) {
|
public function arrayToParams(array $getParams = null, $includeEmpty = true) {
|
||||||
|
|
||||||
if(is_array($getParams)) {
|
if(is_array($getParams)) {
|
||||||
@@ -332,8 +310,9 @@ class RouterBase {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->httpBuildQuery($getParams);
|
return '?' . http_build_query($getParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,8 +367,8 @@ class RouterBase {
|
|||||||
|
|
||||||
$url = rtrim($url, '/') . '/';
|
$url = rtrim($url, '/') . '/';
|
||||||
|
|
||||||
if($getParams !== null && count($getParams)) {
|
if($getParams !== null) {
|
||||||
$url .= '?' . $this->arrayToParams($getParams);
|
$url .= $this->arrayToParams($getParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
@@ -411,8 +390,8 @@ class RouterBase {
|
|||||||
|
|
||||||
$url = parse_url($this->request->getUri(), PHP_URL_PATH);
|
$url = parse_url($this->request->getUri(), PHP_URL_PATH);
|
||||||
|
|
||||||
if(count($getParams)) {
|
if($getParams !== null) {
|
||||||
$url .= '?' . $this->arrayToParams($getParams);
|
$url .= $this->arrayToParams($getParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
|
|||||||
Reference in New Issue
Block a user