Skip to content

Commit 33554fc

Browse files
committed
feature #4456 New validation API usage in Class Constraint Validator (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
2 parents e96ebd3 + e431fdb commit 33554fc

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)