From a2daec4d72e47b9ce07e0bc915834f3594b7f453 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Wed, 26 Feb 2025 12:18:13 +0100 Subject: [PATCH] [Config] Allow using an enum FQCN with `EnumNode` --- components/config/definition.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/components/config/definition.rst b/components/config/definition.rst index 24c142ec5a5..b22d66c2b51 100644 --- a/components/config/definition.rst +++ b/components/config/definition.rst @@ -186,6 +186,25 @@ The configuration can now be written like this:: ->end() ; +You can also use the ``enumClass()`` method to pass the FQCN of an enum +class to the node. This will automatically set the values of the node to +the cases of the enum:: + + $rootNode + ->children() + ->enumNode('delivery') + ->enumClass(Delivery::class) + ->end() + ->end() + ; + +When using a backed enum, the values provided to the node will be casted +to one of the enum cases if possible. + +.. versionadded:: 7.3 + + The ``enumClass()`` method was introduced in Symfony 7.3. + Array Nodes ~~~~~~~~~~~