Web\Url: add set/mergeValues support

This commit is contained in:
Thomas Gelf 2014-06-20 15:50:55 +02:00
parent 199f6e978b
commit afd6b11b7b
2 changed files with 31 additions and 3 deletions

View File

@ -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;
}

View File

@ -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
*