Skip to content

Commit 4d69ef4

Browse files
committed
Merge branch '7.4' into 8.0
* 7.4: [Config] Replace fixXmlConfig() by a new argument of arrayNode()
2 parents 6ffe395 + 878c3fc commit 4d69ef4

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
@@ -269,9 +269,9 @@ Before defining the children of an array node, you can provide options like:
269269
A basic prototyped array configuration can be defined as follows::
270270

271271
$node
272-
->fixXmlConfig('driver')
273272
->children()
274-
->arrayNode('drivers')
273+
// the arguments are the plural and singular variants of the option name
274+
->arrayNode('drivers', 'driver')
275275
->scalarPrototype()->end()
276276
->end()
277277
->end()
@@ -300,9 +300,8 @@ The processed configuration is::
300300
A more complex example would be to define a prototyped array with children::
301301

302302
$node
303-
->fixXmlConfig('connection')
304303
->children()
305-
->arrayNode('connections')
304+
->arrayNode('connections', 'connection')
306305
->arrayPrototype()
307306
->children()
308307
->scalarNode('table')->end()
@@ -373,9 +372,8 @@ the Symfony Config component treats arrays as lists by default.
373372
In order to maintain the array keys use the ``useAttributeAsKey()`` method::
374373

375374
$node
376-
->fixXmlConfig('connection')
377375
->children()
378-
->arrayNode('connections')
376+
->arrayNode('connections', 'connection')
379377
->useAttributeAsKey('name')
380378
->arrayPrototype()
381379
->children()
@@ -718,14 +716,14 @@ normalization would make both of these ``auto_connect``.
718716
``foo-bar_moo`` or if it already exists.
719717

720718
Another difference between YAML and XML is in the way arrays of values may
721-
be represented. In YAML you may have:
719+
be represented. In YAML you may have an option called ``extensions`` (in plural):
722720

723721
.. code-block:: yaml
724722
725723
twig:
726724
extensions: ['twig.extension.foo', 'twig.extension.bar']
727725
728-
and in XML:
726+
and in XML you have a list of options called ``extension`` (in singular):
729727

730728
.. code-block:: xml
731729
@@ -734,33 +732,24 @@ and in XML:
734732
<twig:extension>twig.extension.bar</twig:extension>
735733
</twig:config>
736734
737-
This difference can be removed in normalization by pluralizing the key used
738-
in XML. You can specify that you want a key to be pluralized in this way
739-
with ``fixXmlConfig()``::
735+
This difference can be removed in normalization by defining the singular variant
736+
of the option name using the second argument of the ``arrayNode()`` method::
740737

741738
$rootNode
742-
->fixXmlConfig('extension')
743739
->children()
744-
->arrayNode('extensions')
740+
->arrayNode('extensions', 'extension')
745741
->scalarPrototype()->end()
746742
->end()
747743
->end()
748744
;
749745

750-
If it is an irregular pluralization you can specify the plural to use as
751-
a second argument::
746+
.. versionadded:: 7.4
752747

753-
$rootNode
754-
->fixXmlConfig('child', 'children')
755-
->children()
756-
->arrayNode('children')
757-
// ...
758-
->end()
759-
->end()
760-
;
748+
The second argument of ``arrayNode()`` was introduced in Symfony 7.4. In prior
749+
Symfony versions, you had to define the singular variant using the ``fixXmlConfig()``
750+
method on the root node (``$rootNode->fixXmlConfig('extension')``).
761751

762-
As well as fixing this, ``fixXmlConfig()`` ensures that single XML elements
763-
are still turned into an array. So you may have:
752+
This ensures that single XML elements are still turned into an array. So you may have:
764753

765754
.. code-block:: xml
766755
@@ -775,7 +764,7 @@ and sometimes only:
775764
776765
By default, ``connection`` would be an array in the first case and a string
777766
in the second, making it difficult to validate. You can ensure it is always
778-
an array with ``fixXmlConfig()``.
767+
an array with the second argument of ``arrayNode()``.
779768

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

0 commit comments

Comments
 (0)