Skip to content

Commit e431fdb

Browse files
skwiwouterj
authored andcommitted
New validation API usage in Class Constraint Validator
1 parent 7cc4287 commit e431fdb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cookbook/validation/custom_constraint.rst

+8
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,20 @@ 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+
->atPath('foo')
236+
->addViolation();
237+
238+
// If you're using the old 2.4 validation API
239+
/*
233240
$this->context->addViolationAt(
234241
'foo',
235242
$constraint->message,
236243
array(),
237244
null
238245
);
246+
*/
239247
}
240248
}
241249
}

0 commit comments

Comments
 (0)