@@ -35,8 +35,8 @@ Configuration
35
35
36
36
.. code-block :: php-annotations
37
37
38
- // src/AppBundle /Entity/Author.php
39
- namespace AppBundle \Entity;
38
+ // src/Acme/BlogBundle /Entity/Author.php
39
+ namespace Acme\BlogBundle \Entity;
40
40
41
41
use Symfony\Component\Validator\Constraints as Assert;
42
42
use Symfony\Component\Validator\Context\ExecutionContextInterface;
@@ -56,28 +56,28 @@ Configuration
56
56
57
57
.. code-block :: yaml
58
58
59
- # src/AppBundle /Resources/config/validation.yml
60
- AppBundle \Entity\Author :
59
+ # src/Acme/BlogBundle /Resources/config/validation.yml
60
+ Acme\BlogBundle \Entity\Author :
61
61
constraints :
62
62
- Callback : [validate]
63
63
64
64
.. code-block :: xml
65
65
66
- <!-- src/AppBundle /Resources/config/validation.xml -->
66
+ <!-- src/Acme/BlogBundle /Resources/config/validation.xml -->
67
67
<?xml version =" 1.0" encoding =" UTF-8" ?>
68
68
<constraint-mapping xmlns =" http://symfony.com/schema/dic/constraint-mapping"
69
69
xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
70
70
xsi : schemaLocation =" http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd" >
71
71
72
- <class name =" AppBundle \Entity\Author" >
72
+ <class name =" Acme\BlogBundle \Entity\Author" >
73
73
<constraint name =" Callback" >validate</constraint >
74
74
</class >
75
75
</constraint-mapping >
76
76
77
77
.. code-block :: php
78
78
79
- // src/AppBundle /Entity/Author.php
80
- namespace AppBundle \Entity;
79
+ // src/Acme/BlogBundle /Entity/Author.php
80
+ namespace Acme\BlogBundle \Entity;
81
81
82
82
use Symfony\Component\Validator\Mapping\ClassMetadata;
83
83
use Symfony\Component\Validator\Constraints as Assert;
@@ -187,69 +187,57 @@ You can then use the following configuration to invoke this validator:
187
187
188
188
.. code-block :: php-annotations
189
189
190
- // src/AppBundle /Entity/Author.php
191
- namespace AppBundle \Entity;
190
+ // src/Acme/BlogBundle /Entity/Author.php
191
+ namespace Acme\BlogBundle \Entity;
192
192
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/Acme/BlogBundle/Resources/config/validation.yml
205
+ Acme\BlogBundle\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/Acme/BlogBundle/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 =" Acme\BlogBundle\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
234
- namespace AppBundle \E ntity;
227
+ // src/Acme/BlogBundle /Entity/Author.php
228
+ namespace Acme\BlogBundle \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
@@ -264,11 +252,8 @@ You can then use the following configuration to invoke this validator:
264
252
When configuring the constraint via PHP, you can also pass a closure to the
265
253
constructor of the Callback constraint::
266
254
267
- // src/AppBundle/Entity/Author.php
268
- namespace AppBundle\Entity;
269
-
270
- use Symfony\Component\Validator\ExecutionContextInterface;
271
- use AppBundle\Entity\Author;
255
+ // src/Acme/BlogBundle/Entity/Author.php
256
+ namespace Acme\BlogBundle\Entity;
272
257
273
258
use Symfony\Component\Validator\Mapping\ClassMetadata;
274
259
use Symfony\Component\Validator\Constraints as Assert;
0 commit comments