@@ -19,6 +19,7 @@ class Choice extends Constraint
public $choices;
public $callback;
public $multiple = false;
+ public $strict = false;
public $min = null;
public $max = null;
public $message = 'The value you selected is not a valid choice';
@@ -73,7 +73,7 @@ class ChoiceValidator extends ConstraintValidator
return false;
}
- } elseif (!in_array($value, $choices, true)) {
+ } elseif (!in_array($value, $choices, $constraint->strict)) {
$this->setMessage($constraint->message, array('{{ value }}' => $value));
@@ -182,4 +182,15 @@ class ChoiceValidatorTest extends \PHPUnit_Framework_TestCase
'{{ limit }}' => 2,
));
+
+ public function testStrictIsFalse()
+ {
+ $constraint = new Choice(array(
+ 'choices' => array(1, 2),
+ 'strict' => false,
+ ));
+ $this->assertTrue($this->validator->isValid('2', $constraint));
+ $this->assertTrue($this->validator->isValid(2, $constraint));
+ }