@@ -51,6 +51,8 @@ Configuration
51
51
52
52
use Symfony\Component\Validator\Constraints as Assert;
53
53
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;
54
56
55
57
class Author
56
58
{
@@ -101,6 +103,8 @@ those errors should be attributed::
101
103
102
104
// ...
103
105
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;
104
108
105
109
class Author
106
110
{
@@ -114,16 +118,26 @@ those errors should be attributed::
114
118
115
119
// check if the name is actually a fake name
116
120
if (in_array($this->getFirstName(), $fakeNames)) {
121
+ // If you're using the new 2.5 validation API (you probably are!)
117
122
$context->buildViolation('This name sounds totally fake!')
118
123
->atPath('firstName')
119
124
->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
+ */
120
133
}
121
134
}
122
135
}
123
136
124
137
.. 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.
127
141
128
142
Static Callbacks
129
143
----------------
@@ -138,10 +152,17 @@ have access to the object instance, they receive the object as the first argumen
138
152
139
153
// check if the name is actually a fake name
140
154
if (in_array($object->getFirstName(), $fakeNames)) {
155
+ // If you're using the new 2.5 validation API (you probably are!)
141
156
$context->buildViolation('This name sounds totally fake!')
142
157
->atPath('firstName')
143
158
->addViolation()
144
159
;
160
+
161
+ // If you're using the old 2.4 validation API
162
+ $context->addViolationAt(
163
+ 'firstName',
164
+ 'This name sounds totally fake!'
165
+ );
145
166
}
146
167
}
147
168
@@ -156,6 +177,8 @@ your validation function is ``Vendor\Package\Validator::validate()``::
156
177
namespace Vendor\Package;
157
178
158
179
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;
159
182
160
183
class Validator
161
184
{
0 commit comments