From 193a2642c5414180e9b4583ee9d161573b2f3ee1 Mon Sep 17 00:00:00 2001 From: skwi Date: Wed, 12 Nov 2014 23:24:15 +0100 Subject: [PATCH 1/2] New validation API usage in Class Constraint Validator --- cookbook/validation/custom_constraint.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cookbook/validation/custom_constraint.rst b/cookbook/validation/custom_constraint.rst index f95d311ed20..a814b0f325b 100644 --- a/cookbook/validation/custom_constraint.rst +++ b/cookbook/validation/custom_constraint.rst @@ -230,12 +230,19 @@ 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) + ->addViolation(); + + // If you're using the old 2.4 validation API + /* $this->context->addViolationAt( 'foo', $constraint->message, array(), null ); + */ } } } From 3e87f146d0c60e1b55baf66751378e2063baf1f1 Mon Sep 17 00:00:00 2001 From: skwi Date: Tue, 18 Nov 2014 16:15:33 +0100 Subject: [PATCH 2/2] Added missing `atPath` method for class constraint validator --- cookbook/validation/custom_constraint.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/cookbook/validation/custom_constraint.rst b/cookbook/validation/custom_constraint.rst index a814b0f325b..d6f9f4a3f9a 100644 --- a/cookbook/validation/custom_constraint.rst +++ b/cookbook/validation/custom_constraint.rst @@ -232,6 +232,7 @@ With this, the validator ``validate()`` method gets an object as its first argum 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