From e431fdb55f58b415a7f6eb77699b043c02920037 Mon Sep 17 00:00:00 2001 From: skwi Date: Wed, 12 Nov 2014 23:24:15 +0100 Subject: [PATCH] New validation API usage in Class Constraint Validator --- cookbook/validation/custom_constraint.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cookbook/validation/custom_constraint.rst b/cookbook/validation/custom_constraint.rst index f95d311ed20..d6f9f4a3f9a 100644 --- a/cookbook/validation/custom_constraint.rst +++ b/cookbook/validation/custom_constraint.rst @@ -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 ); + */ } } }