Browse files

Added a getBool() entry for parameters

  • Loading branch information...
1 parent 2ee3dee commit b14b7d90e729e787e3afd4fcd897f39cbdcd0be6 @rikh42 committed Feb 14, 2013
Showing with 29 additions and 0 deletions.
  1. +29 −0 http/RequestParams.php
View
29 http/RequestParams.php
@@ -120,6 +120,35 @@ public function get($name, $default='')
return $this->clean($this->all[$name]);
}
+
+ /**
+ * Returns a bool of true or false from the value
+ * @param $name
+ * @param bool $default
+ * @return bool
+ */
+ public function getBool($name, $default=false)
+ {
+ // Start by looking at the value as a string
+ $value = mb_strtolower($this->getText($name, ''));
+
+ // the word 'true' maps to true
+ if ($value == 'true') {
+ return true;
+ }
+
+ // similar for false
+ if ($value == 'false') {
+ return false;
+ }
+
+ // wasn't either true or false, so try it as an int
+ $value = (bool) $this->getInt($name, $default);
+ return $value;
+ }
+
+
+
//==============================
// getInt
// Gets an int for the named value

0 comments on commit b14b7d9

Please sign in to comment.