Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb7b52ab

Browse files
committed
[Validation] Mention the option to pass stringable objects
1 parent57acff3 commitb7b52ab

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)

[8]ページ先頭

©2009-2025 Movatter.jp