Skip to content

Commit 79ab1e9

Browse files
committed
[Config] Replace fixXmlConfig() by a new argument of arrayNode()
1 parent 004620e commit 79ab1e9

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

β€Žcomponents/config/definition.rst

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ Before defining the children of an array node, you can provide options like:
281281
A basic prototyped array configuration can be defined as follows::
282282

283283
$node
284-
->fixXmlConfig('driver')
285284
->children()
286-
->arrayNode('drivers')
285+
// the arguments are the plural and singular variants of the option name
286+
->arrayNode('drivers', 'driver')
287287
->scalarPrototype()->end()
288288
->end()
289289
->end()
@@ -312,9 +312,8 @@ The processed configuration is::
312312
A more complex example would be to define a prototyped array with children::
313313

314314
$node
315-
->fixXmlConfig('connection')
316315
->children()
317-
->arrayNode('connections')
316+
->arrayNode('connections', 'connection')
318317
->arrayPrototype()
319318
->children()
320319
->scalarNode('table')->end()
@@ -385,9 +384,8 @@ the Symfony Config component treats arrays as lists by default.
385384
In order to maintain the array keys use the ``useAttributeAsKey()`` method::
386385

387386
$node
388-
->fixXmlConfig('connection')
389387
->children()
390-
->arrayNode('connections')
388+
->arrayNode('connections', 'connection')
391389
->useAttributeAsKey('name')
392390
->arrayPrototype()
393391
->children()
@@ -734,14 +732,14 @@ normalization would make both of these ``auto_connect``.
734732
``foo-bar_moo`` or if it already exists.
735733

736734
Another difference between YAML and XML is in the way arrays of values may
737-
be represented. In YAML you may have:
735+
be represented. In YAML you may have an option called ``extensions`` (in plural):
738736

739737
.. code-block:: yaml
740738
741739
twig:
742740
extensions: ['twig.extension.foo', 'twig.extension.bar']
743741
744-
and in XML:
742+
and in XML you have a list of options called ``extension`` (in singular):
745743

746744
.. code-block:: xml
747745
@@ -750,33 +748,24 @@ and in XML:
750748
<twig:extension>twig.extension.bar</twig:extension>
751749
</twig:config>
752750
753-
This difference can be removed in normalization by pluralizing the key used
754-
in XML. You can specify that you want a key to be pluralized in this way
755-
with ``fixXmlConfig()``::
751+
This difference can be removed in normalization by defining the singular variant
752+
of the option name using the second argument of the ``arrayNode()`` method::
756753

757754
$rootNode
758-
->fixXmlConfig('extension')
759755
->children()
760-
->arrayNode('extensions')
756+
->arrayNode('extensions', 'extension')
761757
->scalarPrototype()->end()
762758
->end()
763759
->end()
764760
;
765761

766-
If it is an irregular pluralization you can specify the plural to use as
767-
a second argument::
762+
.. versionadded:: 7.4
768763

769-
$rootNode
770-
->fixXmlConfig('child', 'children')
771-
->children()
772-
->arrayNode('children')
773-
// ...
774-
->end()
775-
->end()
776-
;
764+
The second argument of ``arrayNode()`` was introduced in Symfony 7.4. In prior
765+
Symfony versions, you had to define the singular variant using the ``fixXmlConfig()``
766+
method on the root node (``$rootNode->fixXmlConfig('extension')``).
777767

778-
As well as fixing this, ``fixXmlConfig()`` ensures that single XML elements
779-
are still turned into an array. So you may have:
768+
This ensures that single XML elements are still turned into an array. So you may have:
780769

781770
.. code-block:: xml
782771
@@ -791,7 +780,7 @@ and sometimes only:
791780
792781
By default, ``connection`` would be an array in the first case and a string
793782
in the second, making it difficult to validate. You can ensure it is always
794-
an array with ``fixXmlConfig()``.
783+
an array with the second argument of ``arrayNode()``.
795784

796785
You can further control the normalization process if you need to. For example,
797786
you may want to allow a string to be set and used as a particular key or

0 commit comments

Comments
 (0)