Skip to content

Commit

Permalink
New validation API usage in Class Constraint Validator
Browse files Browse the repository at this point in the history
  • Loading branch information
skwi authored and wouterj committed Nov 28, 2014
1 parent 7cc4287 commit e431fdb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cookbook/validation/custom_constraint.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,20 @@ With this, the validator ``validate()`` method gets an object as its first argum
public function validate($protocol, Constraint $constraint)
{
if ($protocol->getFoo() != $protocol->getBar()) {
// If you're using the new 2.5 validation API (you probably are!)
$this->context->buildViolation($constraint->message)
->atPath('foo')
->addViolation();

// If you're using the old 2.4 validation API
/*
$this->context->addViolationAt(
'foo',
$constraint->message,
array(),
null
);
*/
}
}
}
Expand Down

0 comments on commit e431fdb

Please sign in to comment.