Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Config] Allow enum values in EnumNode #17865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2023
Merged
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
28 changes: 28 additions & 0 deletions components/config/definition.rst
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,34 @@ values::
This will restrict the ``delivery`` options to be either ``standard``,
``expedited`` or ``priority``.

You can also provide enum values to ``enumNode()``. Let's define an enumeration
describing the possible states of the example above::

enum Delivery: string
{
case Standard = 'standard';
case Expedited = 'expedited';
case Priority = 'priority';
}

The configuration can now be written like this::

$rootNode
->children()
->enumNode('delivery')
// You can provide all values of the enum...
->values(Delivery::cases())
// ... or you can pass only some values next to other scalar values
->values([Delivery::Priority, Delivery::Standard, 'other', false])
->end()
->end()
;

.. versionadded:: 6.3

The support of enum values in ``enumNode()`` was introduced
in Symfony 6.3.

Array Nodes
~~~~~~~~~~~

Expand Down