@@ -193,63 +193,51 @@ You can then use the following configuration to invoke this validator:
193
193
use Symfony\Component\Validator\Constraints as Assert;
194
194
195
195
/**
196
- * @Assert\Callback({"AppBundle\MyStaticValidatorClass ", "isAuthorValid "})
196
+ * @Assert\Callback({"Vendor\Package\Validator ", "validate "})
197
197
*/
198
198
class Author
199
199
{
200
200
}
201
201
202
202
.. code-block :: yaml
203
203
204
- # src/AppBundle/Resources/config/validation.yml
205
- AppBundle\E ntity\A uthor:
206
- constraints:
207
- - Callback:
208
- methods:
209
- - [AppBundle\M yStaticValidatorClass, isAuthorValid]
204
+ # src/AppBundle/Resources/config/validation.yml
205
+ AppBundle\Entity\Author :
206
+ constraints :
207
+ - Callback : [Vendor\Package\Validator, validate]
210
208
211
209
.. code-block :: xml
212
210
213
- <!-- src/AppBundle/Resources/config/validation.xml -->
214
- <?xml version="1.0" encoding="UTF-8" ?>
215
- <constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
216
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
217
- xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">
218
-
219
- <class name="AppBundle\E ntity\A uthor">
220
- <constraint name="Callback">
221
- <option name="methods">
222
- <value>
223
- <value>AppBundle\M yStaticValidatorClass</value>
224
- <value>isAuthorValid</value>
225
- </value>
226
- </option>
227
- </constraint>
228
- </class>
229
- </constraint-mapping>
211
+ <!-- src/AppBundle/Resources/config/validation.xml -->
212
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
213
+ <constraint-mapping xmlns =" http://symfony.com/schema/dic/constraint-mapping"
214
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
215
+ xsi : schemaLocation =" http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd" >
216
+
217
+ <class name =" AppBundle\Entity\Author" >
218
+ <constraint name =" Callback" >
219
+ <value >Vendor\Package\Validator</value >
220
+ <value >validate</value >
221
+ </constraint >
222
+ </class >
223
+ </constraint-mapping >
230
224
231
225
.. code-block :: php
232
226
233
- // src/AppBundle/Entity/Author.php
227
+ // src/AppBundle/Entity/Author.php
234
228
namespace AppBundle\Entity;
235
229
236
230
use Symfony\Component\Validator\Mapping\ClassMetadata;
237
231
use Symfony\Component\Validator\Constraints as Assert;
238
232
239
233
class Author
240
234
{
241
- public $name;
242
-
243
235
public static function loadValidatorMetadata(ClassMetadata $metadata)
244
236
{
245
- $metadata->addConstraint(new Callback(array(
246
- 'methods' => array(
247
- array(
248
- 'AppBundle\M yStaticValidatorClass',
249
- 'isAuthorValid',
250
- ),
251
- ),
252
- )));
237
+ $metadata->addConstraint(new Assert\Callback(array(
238
+ 'Vendor\Package\Validator',
239
+ 'validate',
240
+ )));
253
241
}
254
242
}
255
243
@@ -267,8 +255,9 @@ constructor of the Callback constraint::
267
255
// src/AppBundle/Entity/Author.php
268
256
namespace AppBundle\Entity;
269
257
270
- use Symfony\Component\Validator\ExecutionContextInterface;
271
- use AppBundle\Entity\Author;
258
+ use Symfony\Component\Validator\Context\ExecutionContextInterface;
259
+ // if you're using the older 2.4 validation API, you'll need this instead
260
+ // use Symfony\Component\Validator\ExecutionContextInterface;
272
261
273
262
use Symfony\Component\Validator\Mapping\ClassMetadata;
274
263
use Symfony\Component\Validator\Constraints as Assert;
0 commit comments