@@ -207,8 +207,8 @@ constraint.
207
207
}
208
208
}
209
209
210
- If the static callback is stored in a different class, for example ``Util ``,
211
- you can pass the class name and the method as an array.
210
+ If the static callback is stored in a different class, for example ``AppBundle\Entity\Genre ``,
211
+ you can pass the fully-qualified class and the method as an array.
212
212
213
213
.. configuration-block ::
214
214
@@ -222,7 +222,7 @@ you can pass the class name and the method as an array.
222
222
class Author
223
223
{
224
224
/**
225
- * @Assert\Choice(callback={"Util ", "getGenres"})
225
+ * @Assert\Choice(callback={"AppBundle\Entity\Genre ", "getGenres"})
226
226
*/
227
227
protected $genre;
228
228
}
@@ -233,7 +233,7 @@ you can pass the class name and the method as an array.
233
233
AppBundle\Entity\Author :
234
234
properties :
235
235
genre :
236
- - Choice : { callback: [Util , getGenres] }
236
+ - Choice : { callback: [AppBundle\Entity\Genre , getGenres] }
237
237
238
238
.. code-block :: xml
239
239
@@ -247,7 +247,7 @@ you can pass the class name and the method as an array.
247
247
<property name =" genre" >
248
248
<constraint name =" Choice" >
249
249
<option name =" callback" >
250
- <value >Util </value >
250
+ <value >AppBundle\Entity\Genre </value >
251
251
<value >getGenres</value >
252
252
</option >
253
253
</constraint >
@@ -260,6 +260,7 @@ you can pass the class name and the method as an array.
260
260
// src/AppBundle/Entity/Author.php
261
261
namespace AppBundle\Entity;
262
262
263
+ use AppBundle\Entity\Genre;
263
264
use Symfony\Component\Validator\Mapping\ClassMetadata;
264
265
use Symfony\Component\Validator\Constraints as Assert;
265
266
@@ -270,7 +271,7 @@ you can pass the class name and the method as an array.
270
271
public static function loadValidatorMetadata(ClassMetadata $metadata)
271
272
{
272
273
$metadata->addPropertyConstraint('genre', new Assert\Choice(array(
273
- 'callback' => array('Util' , 'getGenres'),
274
+ 'callback' => array(Genre::class , 'getGenres'),
274
275
)));
275
276
}
276
277
}
0 commit comments