From b42b2e1d05867b2dd4cdb3e1b7e278c63001d355 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 12 Dec 2009 15:00:09 -0500 Subject: [PATCH] integer utility for arguments --- lib/action.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/action.php b/lib/action.php index 87d8a43993..dac0e2583c 100644 --- a/lib/action.php +++ b/lib/action.php @@ -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 * -- 2.39.5