lib: Add UrlParams::shiftRequired()
This commit is contained in:
parent
3a2238f737
commit
3d1c3609c0
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue