8000 minor #10758 [Validator] Added new UnexpectedValueException (TimoBakx) · marcinowski/symfony-docs@7cf2d3a · GitHub
[go: up one dir, main page]

Skip to content

Commit 7cf2d3a

Browse files
committed
minor symfony#10758 [Validator] Added new UnexpectedValueException (TimoBakx)
This PR was merged into the 4.2 branch. Discussion ---------- [Validator] Added new UnexpectedValueException Fixes symfony#10551. Commits ------- 643afc8 Added new UnexpectedValueException
2 parents 1c8f873 + 643afc8 commit 7cf2d3a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

validation/custom_constraint.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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`.
9599
The ``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+
97104
Using the new Validator
98105
-----------------------
99106

0 commit comments

Comments
 (0)
0