@@ -114,7 +114,12 @@ those errors should be attributed::
114
114
115
115
// check if the name is actually a fake name
116
116
if (in_array($this->getFirstName(), $fakeNames)) {
117
- $context->addViolationAt('firstName', 'This name sounds totally fake!', array(), null);
117
+ $context->addViolationAt(
118
+ 'firstName',
119
+ 'This name sounds totally fake!',
120
+ array(),
121
+ null
122
+ );
118
123
}
119
124
}
120
125
}
@@ -123,7 +128,7 @@ Static Callbacks
123
128
----------------
124
129
125
130
You can also use the constraint with static methods. Since static methods don't
126
- have access to the object instance, they receive the object as first argument::
131
+ have access to the object instance, they receive the object as the first argument::
127
132
128
133
public static function validate($object, ExecutionContextInterface $context)
129
134
{
@@ -132,7 +137,12 @@ have access to the object instance, they receive the object as first argument::
132
137
133
138
// check if the name is actually a fake name
134
139
if (in_array($object->getFirstName(), $fakeNames)) {
135
- $context->addViolationAt('firstName', 'This name sounds totally fake!', array(), null);
140
+ $context->addViolationAt(
141
+ 'firstName',
142
+ 'This name sounds totally fake!',
143
+ array(),
144
+ null
145
+ );
136
146
}
137
147
}
138
148
@@ -142,7 +152,7 @@ External Callbacks and Closures
142
152
If you want to execute a static callback method that is not located in the class
143
153
of the validated object, you can configure the constraint to invoke an array
144
154
callable as supported by PHP's :phpfunction: `call_user_func ` function. Suppose
145
- your validation function is `Vendor\Package\Validator::validate() `::
155
+ your validation function is `` Vendor\Package\Validator::validate() ` `::
146
156
147
157
namespace Vendor\Package;
148
158
@@ -156,7 +166,7 @@ your validation function is `Vendor\Package\Validator::validate()`::
156
166
}
157
167
}
158
168
159
- You can then use the following configuration to invoke this validator::
169
+ You can then use the following configuration to invoke this validator:
160
170
161
171
.. configuration-block ::
162
172
@@ -173,7 +183,6 @@ You can then use the following configuration to invoke this validator::
173
183
namespace Acme\BlogBundle\Entity;
174
184
175
185
use Symfony\Component\Validator\Constraints as Assert;
176
- use Symfony\Component\Validator\ExecutionContextInterface;
177
186
178
187
/**
179
188
* @Assert\Callback({"Vendor\Package\Validator", "validate"})
@@ -212,17 +221,17 @@ You can then use the following configuration to invoke this validator::
212
221
{
213
222
$metadata->addConstraint(new Assert\Callback(array(
214
223
'Vendor\Package\Validator',
215
- 'validate'
224
+ 'validate',
216
225
)));
217
226
}
218
227
}
219
228
220
229
.. note ::
221
230
222
- The Callback constraint does *not * support global callback functions or
223
- It is * not * possible to specify a global function or a :term: `service `
224
- method as callback. To validate using a service, you should
225
- :doc: `create a custom validation constraint</cookbook/validation/custom_constraint> `
231
+ The Callback constraint does *not * support global callback functions nor
232
+ is it possible to specify a global function or a :term: `service ` method
233
+ as callback. To validate using a service, you should
234
+ :doc: `create a custom validation constraint </cookbook/validation/custom_constraint >`
226
235
and add that new constraint to your class.
227
236
228
237
When configuring the constraint via PHP, you can also pass a closure to the
@@ -252,20 +261,20 @@ Options
252
261
callback
253
262
~~~~~~~~
254
263
255
- **type **: ``string ``, ``array `` or ``Closure `` [:ref: `default option<validation-default-option> `]
264
+ **type **: ``string ``, ``array `` or ``Closure `` [:ref: `default option <validation-default-option >`]
256
265
257
266
The callback option accepts three different formats for specifying the
258
267
callback method:
259
268
260
- * A **string ** containing the name of a concrete or static method.
269
+ * A **string ** containing the name of a concrete or static method;
261
270
262
- * An array callable with the format ``array('<Class>', '<method>') ``.
271
+ * An array callable with the format ``array('<Class>', '<method>') ``;
263
272
264
273
* A closure.
265
274
266
275
Concrete callbacks receive an :class: `Symfony\\ Component\\ Validator\\ ExecutionContextInterface `
267
276
instance as only argument.
268
277
269
- Static or closure callbacks receive the validated object as first argument
278
+ Static or closure callbacks receive the validated object as the first argument
270
279
and the :class: `Symfony\\ Component\\ Validator\\ ExecutionContextInterface `
271
- instance as second argument.
280
+ instance as the second argument.
0 commit comments