Added validator for boolean

This commit is contained in:
Big Ginger Nerd 2013-10-15 14:59:34 +02:00
parent 247f6f3112
commit 89352fcc15
2 changed files with 19 additions and 1 deletions

View File

@ -23,7 +23,8 @@ return array(
'dateFormat' => "must be date with format '%s'",
'dateBefore' => "must be date before '%s'",
'dateAfter' => "must be date after '%s'",
'contains' => "must contain %s"
'contains' => "must contain %s",
'boolean' => "must be a boolean",
);

View File

@ -430,6 +430,23 @@ class Validator
return $vtime > $ptime;
}
/**
* Validate that a field contains a boolean.
* If $params[0] is true, it also check for string == true.
*
* @param string $field
* @param mixed $value
* @param array $params
* @return bool
*/
protected function validateBoolean($field, $value, $params)
{
if(isset($params[0]) && $params[0] == true && $value == "true") {
$value = true;
}
return (is_bool($value)) ? true : false;
}
/**
* Get array of fields and data
*/