cli: Add Params::shiftRequired()
This commit is contained in:
parent
ccaebd1d73
commit
338fad5da9
|
@ -258,6 +258,30 @@ class Params
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put the given value onto the argument stack
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue