@@ -51,6 +51,8 @@ Configuration
5151
5252 use Symfony\Component\Validator\Constraints as Assert;
5353 use Symfony\Component\Validator\Context\ExecutionContextInterface;
54+ // if you're using the older 2.4 validation API, you'll need this instead
55+ // use Symfony\Component\Validator\ExecutionContextInterface;
5456
5557 class Author
5658 {
@@ -101,6 +103,8 @@ those errors should be attributed::
101103
102104 // ...
103105 use Symfony\Component\Validator\Context\ExecutionContextInterface;
106+ // if you're using the older 2.4 validation API, you'll need this instead
107+ // use Symfony\Component\Validator\ExecutionContextInterface;
104108
105109 class Author
106110 {
@@ -114,16 +118,26 @@ those errors should be attributed::
114118
115119 // check if the name is actually a fake name
116120 if (in_array($this->getFirstName(), $fakeNames)) {
121+ // If you're using the new 2.5 validation API (you probably are!)
117122 $context->buildViolation('This name sounds totally fake!')
118123 ->atPath('firstName')
119124 ->addViolation();
125+
126+ // If you're using the old 2.4 validation API
127+ /*
128+ $context->addViolationAt(
129+ 'firstName',
130+ 'This name sounds totally fake!'
131+ );
132+ */
120133 }
121134 }
122135 }
123136
124137..versionadded ::2.5
125- The ``buildViolation `` method was added in Symfony 2.5. For usage examples with
126- older Symfony versions, see the corresponding versions of this documentation page.
138+ The ``buildViolation `` method was added in Symfony 2.5. For usage examples
139+ with older Symfony versions, see the corresponding versions of this documentation
140+ page.
127141
128142Static Callbacks
129143----------------
@@ -138,10 +152,17 @@ have access to the object instance, they receive the object as the first argumen
138152
139153 // check if the name is actually a fake name
140154 if (in_array($object->getFirstName(), $fakeNames)) {
155+ // If you're using the new 2.5 validation API (you probably are!)
141156 $context->buildViolation('This name sounds totally fake!')
142157 ->atPath('firstName')
143158 ->addViolation()
144159 ;
160+
161+ // If you're using the old 2.4 validation API
162+ $context->addViolationAt(
163+ 'firstName',
164+ 'This name sounds totally fake!'
165+ );
145166 }
146167 }
147168
@@ -156,6 +177,8 @@ your validation function is ``Vendor\Package\Validator::validate()``::
156177 namespace Vendor\Package;
157178
158179 use Symfony\Component\Validator\Context\ExecutionContextInterface;
180+ // if you're using the older 2.4 validation API, you'll need this instead
181+ // use Symfony\Component\Validator\ExecutionContextInterface;
159182
160183 class Validator
161184 {