Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita6d7053

Browse files
committed
minor#10679 Improved the example about Choice constraint callback (javiereguiluz)
This PR was merged into the 2.8 branch.Discussion----------Improved the example about Choice constraint callbackI don't know if this is 100% correct, but in a real Symfony project, the `callback` without the FQCN didn't work (at least when using the PHP annotations).Commits-------dece243 Improved the example about Choice constraint callback
2 parents88939de +dece243 commita6d7053

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

‎reference/constraints/Choice.rst‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ constraint.
207207
}
208208
}
209209
210-
If the static callback is stored in a different class, for example ``Util``,
211-
you can pass theclass 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 thefully-qualified class and the method as an array.
212212

213213
..configuration-block::
214214

@@ -222,7 +222,7 @@ you can pass the class name and the method as an array.
222222
class Author
223223
{
224224
/**
225-
* @Assert\Choice(callback={"Util", "getGenres"})
225+
* @Assert\Choice(callback={"AppBundle\Entity\Genre", "getGenres"})
226226
*/
227227
protected $genre;
228228
}
@@ -233,7 +233,7 @@ you can pass the class name and the method as an array.
233233
AppBundle\Entity\Author:
234234
properties:
235235
genre:
236-
-Choice:{ callback: [Util, getGenres] }
236+
-Choice:{ callback: [AppBundle\Entity\Genre, getGenres] }
237237
238238
..code-block::xml
239239
@@ -247,7 +247,7 @@ you can pass the class name and the method as an array.
247247
<propertyname="genre">
248248
<constraintname="Choice">
249249
<optionname="callback">
250-
<value>Util</value>
250+
<value>AppBundle\Entity\Genre</value>
251251
<value>getGenres</value>
252252
</option>
253253
</constraint>
@@ -260,6 +260,7 @@ you can pass the class name and the method as an array.
260260
// src/AppBundle/Entity/Author.php
261261
namespace AppBundle\Entity;
262262
263+
use AppBundle\Entity\Genre;
263264
use Symfony\Component\Validator\Mapping\ClassMetadata;
264265
use Symfony\Component\Validator\Constraints as Assert;
265266
@@ -270,7 +271,7 @@ you can pass the class name and the method as an array.
270271
public static function loadValidatorMetadata(ClassMetadata $metadata)
271272
{
272273
$metadata->addPropertyConstraint('genre', new Assert\Choice(array(
273-
'callback' => array('Util', 'getGenres'),
274+
'callback' => array(Genre::class, 'getGenres'),
274275
)));
275276
}
276277
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp