Skip to content

Commit f06203a

Browse files
committed
[Form] Improved ValidatorTypeGuesser to interpret the constraints True and False
1 parent c3b79f1 commit f06203a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,13 @@ public function guessTypeForConstraint(Constraint $constraint)
171171

172172
case 'Symfony\Component\Validator\Constraints\Url':
173173
return new TypeGuess('url', array(), Guess::HIGH_CONFIDENCE);
174+
175+
case 'Symfony\Component\Validator\Constraints\True':
176+
case 'Symfony\Component\Validator\Constraints\False':
177+
return new TypeGuess('checkbox', array(), Guess::MEDIUM_CONFIDENCE);
174178
}
179+
180+
return null;
175181
}
176182

177183
/**
@@ -186,8 +192,11 @@ public function guessRequiredForConstraint(Constraint $constraint)
186192
switch (get_class($constraint)) {
187193
case 'Symfony\Component\Validator\Constraints\NotNull':
188194
case 'Symfony\Component\Validator\Constraints\NotBlank':
195+
case 'Symfony\Component\Validator\Constraints\True':
189196
return new ValueGuess(true, Guess::HIGH_CONFIDENCE);
190197
}
198+
199+
return null;
191200
}
192201

193202
/**
@@ -215,6 +224,8 @@ public function guessMaxLengthForConstraint(Constraint $constraint)
215224
case 'Symfony\Component\Validator\Constraints\Size':
216225
return new ValueGuess(strlen((string) $constraint->max), Guess::LOW_CONFIDENCE);
217226
}
227+
228+
return null;
218229
}
219230

220231
/**
@@ -250,6 +261,8 @@ public function guessPatternForConstraint(Constraint $constraint)
250261
}
251262
break;
252263
}
264+
265+
return null;
253266
}
254267

255268
/**

0 commit comments

Comments
 (0)