mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-27 15:54:03 +02:00
lib: Add UrlParams::shiftRequired()
This commit is contained in:
parent
3a2238f737
commit
3d1c3609c0
@ -138,6 +138,30 @@ class UrlParams
|
|||||||
return $ret;
|
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)
|
public function addEncoded($param, $value = true)
|
||||||
{
|
{
|
||||||
$this->params[] = array($param, $this->cleanupValue($value));
|
$this->params[] = array($param, $this->cleanupValue($value));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user