Skip to content

Commit

Permalink
feature #4456 New validation API usage in Class Constraint Validator …
Browse files Browse the repository at this point in the history
…(skwi)

This PR was squashed before being merged into the 2.5 branch (closes #4456).

Discussion
----------

New validation API usage in Class Constraint Validator

| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | no
| Applies to    | 2.5
| Fixed tickets |

The code in the documentation about Class Constraint Validator was still using the deprecated validation API

Commits
-------

e431fdb New validation API usage in Class Constraint Validator
  • Loading branch information
wouterj committed Nov 28, 2014
2 parents e96ebd3 + e431fdb commit 33554fc
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 33554fc

Please sign in to comment.