Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions reference/constraints/Choice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ If your valid choice list is simple, you can pass them in directly via the
{
public const GENRES = ['fiction', 'non-fiction'];

#[Assert\Choice(['New York', 'Berlin', 'Tokyo'])]
#[Assert\Choice(choices: ['New York', 'Berlin', 'Tokyo'])]
protected string $city;

#[Assert\Choice(choices: Author::GENRES, message: 'Choose a valid genre.')]
Expand All @@ -47,7 +47,8 @@ If your valid choice list is simple, you can pass them in directly via the
App\Entity\Author:
properties:
city:
- Choice: [New York, Berlin, Tokyo]
- Choice:
choices: [New York, Berlin, Tokyo]
genre:
- Choice:
choices: [fiction, non-fiction]
Expand All @@ -64,9 +65,11 @@ If your valid choice list is simple, you can pass them in directly via the
<class name="App\Entity\Author">
<property name="city">
<constraint name="Choice">
<value>New York</value>
<value>Berlin</value>
<value>Tokyo</value>
<option name="choices">
<value>New York</value>
<value>Berlin</value>
<value>Tokyo</value>
</option>
</constraint>
</property>
<property name="genre">
Expand Down Expand Up @@ -97,7 +100,7 @@ If your valid choice list is simple, you can pass them in directly via the
{
$metadata->addPropertyConstraint(
'city',
new Assert\Choice(['New York', 'Berlin', 'Tokyo'])
new Assert\Choice(choices: ['New York', 'Berlin', 'Tokyo'])
);

$metadata->addPropertyConstraint('genre', new Assert\Choice(
Expand All @@ -107,6 +110,12 @@ If your valid choice list is simple, you can pass them in directly via the
}
}

.. deprecated:: 7.4

Passing an array of choices as the first argument of the ``Choice`` constraint
is deprecated and will stop working in Symfony 8.0. Instead, pass the choices
using the ``choices:`` named argument.

Supplying the Choices with a Callback Function
----------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion validation/raw_values.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Validation of arrays is possible using the ``Collection`` constraint::
]),
'email' => new Assert\Email(),
'simple' => new Assert\Length(['min' => 102]),
'eye_color' => new Assert\Choice([3, 4]),
'eye_color' => new Assert\Choice(choices: [3, 4]),
'file' => new Assert\File(),
'password' => new Assert\Length(['min' => 60]),
'tags' => new Assert\Optional([
Expand Down