1 回答

TA贡献2080条经验 获得超4个赞
您可以在验证上传递该选项。message
App\Entity\User:
properties:
plainPassword:
- Symfony\Component\Validator\Constraints\NotCompromisedPassword:
message: "You error message"
但是,如果要将约束验证为验证器,则可以使用:
class MyValidator extends ConstraintValidator
{
public function validate($value, Constraint $chain)
{
// Previous check...
$groups = $this->context->getGroup();
$violations = $this->context->getViolations();
$current = $violations->count();
// Execute the new constraint
$this->context->getValidator()
->inContext($this->context)
->validate($value, new MyOtherConstraint(), $groups);
// Check if the constraint has failed
if ($violations->count() !== $current) {
return;
}
}
}
- 1 回答
- 0 关注
- 123 浏览
添加回答
举报