lib: Add UrlParams::shiftRequired()

This commit is contained in:
Eric Lippmann 2015-05-19 17:21:53 +02:00
parent 3a2238f737
commit 3d1c3609c0
1 changed files with 24 additions and 0 deletions

View File

@ -138,6 +138,30 @@ class UrlParams
return $ret;
}
/**
* Require and remove a parameter
*
* @param string $name Name of the parameter
* @param bool $strict Whether the parameter's value must not be the empty string
*
* @return mixed
*
* @throws MissingParameterException If the parameter was not given
*/
public function shiftRequired($name, $strict = true)
{
if ($this->has($name)) {
$value = $this->get($name);
if (! $strict || strlen($value) > 0) {
$this->shift($name);
return $value;
}
}
$e = new MissingParameterException(t('Required parameter \'%s\' missing'), $name);
$e->setParameter($name);
throw $e;
}
public function addEncoded($param, $value = true)
{
$this->params[] = array($param, $this->cleanupValue($value));