Commit 88fc0f1e authored by romanb's avatar romanb

added enum type validation

parent 34f527ad
...@@ -254,38 +254,40 @@ class Doctrine_Validator extends Doctrine_Object ...@@ -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;
}
}
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment