summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2009-12-12 15:00:09 -0500
committerEvan Prodromou <evan@status.net>2009-12-12 15:00:09 -0500
commitb42b2e1d05867b2dd4cdb3e1b7e278c63001d355 (patch)
tree61c590625642da7f84850588728abb7d9b1a95fd
parent89256fa754c1e03b822b8eeac388cc822b3c58ca (diff)
integer utility for arguments
-rw-r--r--lib/action.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/action.php b/lib/action.php
index 87d8a4399..dac0e2583 100644
--- a/lib/action.php
+++ b/lib/action.php
@@ -952,6 +952,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
*
* @param string $msg error message to display