integer utility for arguments

This commit is contained in:
Evan Prodromou 2009-12-12 15:00:09 -05:00
parent 89256fa754
commit b42b2e1d05
1 changed files with 30 additions and 0 deletions

View File

@ -951,6 +951,36 @@ class Action extends HTMLOutputter // lawsuit
}
}
/**
* Integer value of an argument
*
* @param string $key query key we're interested in
* @param string $defValue optional default value (default null)
* @param string $maxValue optional max value (default null)
* @param string $minValue optional min value (default null)
*
* @return integer integer value
*/
function int($key, $defValue=null, $maxValue=null, $minValue=null)
{
$arg = strtolower($this->trimmed($key));
if (is_null($arg) || !is_integer($arg)) {
return $defValue;
}
if (!is_null($maxValue)) {
$arg = min($arg, $maxValue);
}
if (!is_null($minValue)) {
$arg = max($arg, $minValue);
}
return $arg;
}
/**
* Server error
*