mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-30 23:01:52 +00:00
Added validator for boolean
This commit is contained in:
parent
247f6f3112
commit
89352fcc15
@ -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",
|
||||
);
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user