diff --git a/library/Icinga/Web/Url.php b/library/Icinga/Web/Url.php index 3f94a0410..2006cb180 100644 --- a/library/Icinga/Web/Url.php +++ b/library/Icinga/Web/Url.php @@ -174,7 +174,7 @@ class Url } // TODO: This has been used by former filter implementation, remove it: if (isset($urlParts['query'])) { - $params = UrlParams::fromQueryString($urlParts['query'])->addValues($params); + $params = UrlParams::fromQueryString($urlParts['query'])->mergeValues($params); } $fragment = self::getUrlFragment($url); @@ -381,8 +381,9 @@ class Url } $this->params = $urlParams; } else { - // TODO: ProgrammingError? - throw new \Exception('Url, params, WTF'); + throw new ProgrammingError( + 'Url params needs to be either an array or an UrlParams instance' + ); } return $this; } diff --git a/library/Icinga/Web/UrlParams.php b/library/Icinga/Web/UrlParams.php index a9d0eb79a..ecb9c5230 100644 --- a/library/Icinga/Web/UrlParams.php +++ b/library/Icinga/Web/UrlParams.php @@ -156,6 +156,33 @@ class UrlParams return $this; } + protected function clearValues() + { + $this->params = array(); + $this->index = array(); + } + + public function mergeValues($param, $values = null) + { + if ($values === null && is_array($param)) { + foreach ($param as $k => $v) { + $this->set($k, $v); + } + } else { + foreach ($values as $value) { + $this->set($param, $value); + } + } + + return $this; + } + + public function setValues($param, $values = null) + { + $this->clearValues(); + return $this->addValues($param, $values); + } + /** * Add the given parameter with the given value in front of all other values *