8000 [Validation] Mention the option to pass stringable objects · symfony/symfony-docs@b7b52ab · GitHub
[go: up one dir, main page]

Skip to content

Commit b7b52ab

Browse files
committed
[Validation] Mention the option to pass stringable objects
1 parent 57acff3 commit b7b52ab

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

validation/custom_constraint.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,19 @@ The validator class is also simple, and only has one required method ``validate(
8585
}
8686

8787
if (!preg_match('/^[a-zA-Z0-9]+$/', $value, $matches)) {
88+
// the argument must be a string or an object implementing __toString()
8889
$this->context->buildViolation($constraint->message)
8990
->setParameter('{{ string }}', $value)
9091
->addViolation();
9192
}
9293
}
9394
}
9495

96+
.. versionadded:: 4.4
97+
98+
The feature to allow passing an object as the ``buildViolation()`` argument
99+
was introduced in Symfony 4.4.
100+
95101
Inside ``validate``, you don't need to return a value. Instead, you add violations
96102
to the validator's ``context`` property and a value will be considered valid
97103
if it causes no violations. The ``buildViolation()`` method takes the error

0 commit comments

Comments
 (0)
0