Skip to content

Commit

Permalink
[Form] Improved ValidatorTypeGuesser to interpret the constraints Tru…
Browse files Browse the repository at this point in the history
…e and False
  • Loading branch information
webmozart committed Jul 11, 2012
1 parent c3b79f1 commit f06203a
Showing 1 changed file with 13 additions and 0 deletions.
Expand Up @@ -171,7 +171,13 @@ public function guessTypeForConstraint(Constraint $constraint)

case 'Symfony\Component\Validator\Constraints\Url':
return new TypeGuess('url', array(), Guess::HIGH_CONFIDENCE);

case 'Symfony\Component\Validator\Constraints\True':
case 'Symfony\Component\Validator\Constraints\False':
return new TypeGuess('checkbox', array(), Guess::MEDIUM_CONFIDENCE);
}

return null;
}

/**
Expand All @@ -186,8 +192,11 @@ public function guessRequiredForConstraint(Constraint $constraint)
switch (get_class($constraint)) {
case 'Symfony\Component\Validator\Constraints\NotNull':
case 'Symfony\Component\Validator\Constraints\NotBlank':
case 'Symfony\Component\Validator\Constraints\True':
return new ValueGuess(true, Guess::HIGH_CONFIDENCE);
}

return null;
}

/**
Expand Down Expand Up @@ -215,6 +224,8 @@ public function guessMaxLengthForConstraint(Constraint $constraint)
case 'Symfony\Component\Validator\Constraints\Size':
return new ValueGuess(strlen((string) $constraint->max), Guess::LOW_CONFIDENCE);
}

return null;
}

/**
Expand Down Expand Up @@ -250,6 +261,8 @@ public function guessPatternForConstraint(Constraint $constraint)
}
break;
}

return null;
}

/**
Expand Down

0 comments on commit f06203a

Please sign in to comment.