@@ -66,7 +66,7 @@ The validator class is also simple, and only has one required method ``validate(
6666 public function validate($value, Constraint $constraint)
6767 {
6868 if (!$constraint instanceof ContainsAlphanumeric) {
69- throw new UnexpectedTypeException($constraint, ContainsAlphanumeric::class);
69+ throw new UnexpectedTypeException($constraint, ContainsAlphanumeric::class);
7070 }
7171
7272 // custom constraints should ignore null and empty values to allow
@@ -76,7 +76,11 @@ The validator class is also simple, and only has one required method ``validate(
7676 }
7777
7878 if (!is_string($value)) {
79- throw new UnexpectedTypeException($value, 'string');
79+ // throw this exception if your validator cannot handle the passed type so that it can be marked as invalid
80+ throw new UnexpectedValueException($value, 'string');
81+
82+ // separate multiple types using pipes
83+ // throw new UnexpectedValueException($value, 'string|int');
8084 }
8185
8286 if (!preg_match('/^[a-zA-Z0-9]+$/', $value, $matches)) {
@@ -94,6 +98,9 @@ message as its argument and returns an instance of
9498:class: `Symfony\\ Component\\ Validator\\ Violation\\ ConstraintViolationBuilderInterface `.
9599The ``addViolation() `` method call finally adds the violation to the context.
96100
101+ .. versionadded :: 4.2
102+ The ``UnexpectedValueException `` was introduced in Symfony 4.2.
103+
97104Using the new Validator
98105-----------------------
99106
0 commit comments