Skip to content

Commit 90a4828

Browse files
[Config] Allow enum values in EnumNode
1 parent 1637b92 commit 90a4828

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

components/config/definition.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,34 @@ values::
151151
This will restrict the ``delivery`` options to be either ``standard``,
152152
``expedited`` or ``priority``.
153153

154+
You can also provide enum values to ``enumNode()``. Let's define an enumeration
155+
describing the possible states of the example above::
156+
157+
enum Delivery: string
158+
{
159+
case Standard = 'standard';
160+
case Expedited = 'expedited';
161+
case Priority = 'priority';
162+
}
163+
164+
The configuration can now be written like this::
165+
166+
$rootNode
167+
->children()
168+
->enumNode('delivery')
169+
// You can provide all values of the enum...
170+
->values(Delivery::cases())
171+
// ... or you can pass only some values next to other scalar values
172+
->values([Delivery::Priority, Delivery::Standard, 'other', false])
173+
->end()
174+
->end()
175+
;
176+
177+
.. versionadded:: 6.3
178+
179+
The support of enum values in ``enumNode()`` was introduced
180+
in Symfony 6.3.
181+
154182
Array Nodes
155183
~~~~~~~~~~~
156184

0 commit comments

Comments
 (0)