even better boolean handling

darcs-hash:20080529152304-84dde-b0b0ea1f919701c2d821d9bf589a30db34dcc015.gz
This commit is contained in:
Evan Prodromou 2008-05-29 11:23:04 -04:00
parent b153ac5b1b
commit 22577b17ed

View File

@ -48,14 +48,16 @@ class Action { // lawsuit
} }
function boolean($key, $def=false) { function boolean($key, $def=false) {
$arg = $this->arg($key); $arg = strtolower($this->trimmed($key));
return (is_null($arg)) ? $def :
(strcasecmp($arg, 'true') == 0) ? true : if (is_null($arg)) {
(strcasecmp($arg, 'yes') == 0) ? true : return $def;
(strcasecmp($arg, '1') == 0) ? true : } else if (in_array($arg, array('true', 'yes', '1'))) {
(strcasecmp($arg, 'false') == 0) ? false : return true;
(strcasecmp($arg, 'no') == 0) ? false : } else if (in_array($arg, array('false', 'no', '0'))) {
(strcasecmp($arg, '0') == 0) ? false : return false;
$def; } else {
return $def;
}
} }
} }