Skip to content

Commit 91a9140

Browse files
committed
Merge branch '2.8' into 3.4
* 2.8: Improved the example about Choice constraint callback
2 parents c9b77a7 + a6d7053 commit 91a9140

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

reference/constraints/Choice.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ constraint.
210210
}
211211
}
212212
213-
If the callback is stored in a different class and is static, for example ``Util``,
213+
If the callback is stored in a different class and is static, for example ``AppBundle\Entity\Genre``,
214214
you can pass the class name and the method as an array.
215215

216216
.. configuration-block::
@@ -225,7 +225,7 @@ you can pass the class name and the method as an array.
225225
class Author
226226
{
227227
/**
228-
* @Assert\Choice(callback={"Util", "getGenres"})
228+
* @Assert\Choice(callback={"AppBundle\Entity\Genre", "getGenres"})
229229
*/
230230
protected $genre;
231231
}
@@ -236,7 +236,7 @@ you can pass the class name and the method as an array.
236236
AppBundle\Entity\Author:
237237
properties:
238238
genre:
239-
- Choice: { callback: [Util, getGenres] }
239+
- Choice: { callback: [AppBundle\Entity\Genre, getGenres] }
240240
241241
.. code-block:: xml
242242
@@ -250,7 +250,7 @@ you can pass the class name and the method as an array.
250250
<property name="genre">
251251
<constraint name="Choice">
252252
<option name="callback">
253-
<value>Util</value>
253+
<value>AppBundle\Entity\Genre</value>
254254
<value>getGenres</value>
255255
</option>
256256
</constraint>
@@ -263,6 +263,7 @@ you can pass the class name and the method as an array.
263263
// src/AppBundle/Entity/Author.php
264264
namespace AppBundle\Entity;
265265
266+
use AppBundle\Entity\Genre;
266267
use Symfony\Component\Validator\Mapping\ClassMetadata;
267268
use Symfony\Component\Validator\Constraints as Assert;
268269
@@ -273,7 +274,7 @@ you can pass the class name and the method as an array.
273274
public static function loadValidatorMetadata(ClassMetadata $metadata)
274275
{
275276
$metadata->addPropertyConstraint('genre', new Assert\Choice(array(
276-
'callback' => array('Util', 'getGenres'),
277+
'callback' => array(Genre::class, 'getGenres'),
277278
)));
278279
}
279280
}

0 commit comments

Comments
 (0)