Skip to content

Commit 193a264

Browse files
committed
New validation API usage in Class Constraint Validator
1 parent 7cc4287 commit 193a264

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

cookbook/validation/custom_constraint.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,19 @@ With this, the validator ``validate()`` method gets an object as its first argum
230230
public function validate($protocol, Constraint $constraint)
231231
{
232232
if ($protocol->getFoo() != $protocol->getBar()) {
233+
// If you're using the new 2.5 validation API (you probably are!)
234+
$this->context->buildViolation($constraint->message)
235+
->addViolation();
236+
237+
// If you're using the old 2.4 validation API
238+
/*
233239
$this->context->addViolationAt(
234240
'foo',
235241
$constraint->message,
236242
array(),
237243
null
238244
);
245+
*/
239246
}
240247
}
241248
}

0 commit comments

Comments
 (0)