Skip to content

Commit

Permalink
[Validators][Type] Added support for ctype_* functions + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamindulau committed Nov 1, 2011
1 parent 6201082 commit 88af2a4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Constraints/TypeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ public function isValid($value, Constraint $constraint)

$type = strtolower($constraint->type);
$type = $type == 'boolean' ? 'bool' : $constraint->type;
$function = 'is_'.$type;
$isFunction = 'is_'.$type;
$ctypeFunction = 'ctype_'.$type;

if (function_exists($function) && call_user_func($function, $value)) {
if (function_exists($isFunction) && call_user_func($isFunction, $value)) {
return true;
} else if (function_exists($ctypeFunction) && call_user_func($ctypeFunction, $value)) {
return true;
} else if ($value instanceof $constraint->type) {
return true;
Expand Down

0 comments on commit 88af2a4

Please sign in to comment.