From b4f64aa40af89cde52d2988ebea58c16d47971f2 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Sat, 31 Jan 2026 21:41:21 +0100 Subject: [PATCH] [Config] Document ArrayNodeDefinition::acceptAndWrap() method --- components/config/definition.rst | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/components/config/definition.rst b/components/config/definition.rst index 2b1841bc24..23c2cc3705 100644 --- a/components/config/definition.rst +++ b/components/config/definition.rst @@ -278,6 +278,34 @@ Before defining the children of an array node, you can provide options like: Allows extra config keys to be specified under an array without throwing an exception. +``acceptAndWrap()`` + Declares which alternative scalar types (e.g., ``string``, ``int``, ``bool``) + should be accepted at an array node level and automatically wrapped into arrays. + This is particularly useful for generating more precise type hints in config + builder classes instead of falling back to ``mixed``:: + + $rootNode + ->children() + ->arrayNode('connections') + ->acceptAndWrap('string') + ->scalarPrototype()->end() + ->end() + ->end() + ; + + With this configuration, users can provide either an array of strings or a + single string that will be automatically wrapped into an array: + + .. code-block:: yaml + + # Both configurations are valid: + connections: ['mysql', 'sqlite'] + connections: 'mysql' # automatically wrapped as ['mysql'] + + .. versionadded:: 7.4 + + The ``acceptAndWrap()`` method was introduced in Symfony 7.4. + A basic prototyped array configuration can be defined as follows:: $node