added enum type validation
This commit is contained in:
parent
34f527adfc
commit
88fc0f1e95
1 changed files with 34 additions and 32 deletions
|
@ -254,38 +254,40 @@ class Doctrine_Validator extends Doctrine_Object
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function isValidType($var, $type)
|
public static function isValidType($var, $type)
|
||||||
{
|
{
|
||||||
if ($var === null) {
|
if ($var === null) {
|
||||||
return true;
|
return true;
|
||||||
} else if (is_object($var)) {
|
} else if (is_object($var)) {
|
||||||
return $type == 'object';
|
return $type == 'object';
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'float':
|
case 'float':
|
||||||
case 'double':
|
case 'double':
|
||||||
return (String)$var == strval(floatval($var));
|
return (String)$var == strval(floatval($var));
|
||||||
case 'integer':
|
case 'integer':
|
||||||
return (String)$var == strval(intval($var));
|
return (String)$var == strval(intval($var));
|
||||||
case 'string':
|
case 'string':
|
||||||
return is_string($var) || is_int($var) || is_float($var);
|
return is_string($var) || is_int($var) || is_float($var);
|
||||||
case 'array':
|
case 'array':
|
||||||
return is_array($var);
|
return is_array($var);
|
||||||
case 'object':
|
case 'object':
|
||||||
return is_object($var);
|
return is_object($var);
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
return is_bool($var);
|
return is_bool($var);
|
||||||
case 'timestamp':
|
case 'timestamp':
|
||||||
// todo: validate the timestamp is in YYYY-MM-DD HH:MM:SS format
|
// todo: validate the timestamp is in YYYY-MM-DD HH:MM:SS format
|
||||||
return true;
|
return true;
|
||||||
case 'date':
|
case 'date':
|
||||||
$validator = self::getValidator('date');
|
$validator = self::getValidator('date');
|
||||||
return $validator->validate($var);
|
return $validator->validate($var);
|
||||||
default:
|
case 'enum':
|
||||||
return false;
|
return is_string($var) || is_int($var);
|
||||||
}
|
default:
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue