8000 feature #12822 [Validation] Mention the option to pass stringable obj… · symfony/symfony-docs@444d03e · GitHub
[go: up one dir, main page]

Skip to content

Commit 444d03e

Browse files
committed
feature #12822 [Validation] Mention the option to pass stringable objects (javiereguiluz)
This PR was merged into the 4.4 branch. Discussion ---------- [Validation] Mention the option to pass stringable objects Fixes #12123. Commits ------- b7b52ab [Validation] Mention the option to pass stringable objects
2 parents 4d42897 + b7b52ab commit 444d03e

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