@@ -269,9 +269,9 @@ Before defining the children of an array node, you can provide options like:
269
269
A basic prototyped array configuration can be defined as follows::
270
270
271
271
$node
272
- ->fixXmlConfig('driver')
273
272
->children()
274
- ->arrayNode('drivers')
273
+ // the arguments are the plural and singular variants of the option name
274
+ ->arrayNode('drivers', 'driver')
275
275
->scalarPrototype()->end()
276
276
->end()
277
277
->end()
@@ -300,9 +300,8 @@ The processed configuration is::
300
300
A more complex example would be to define a prototyped array with children::
301
301
302
302
$node
303
- ->fixXmlConfig('connection')
304
303
->children()
305
- ->arrayNode('connections')
304
+ ->arrayNode('connections', 'connection' )
306
305
->arrayPrototype()
307
306
->children()
308
307
->scalarNode('table')->end()
@@ -373,9 +372,8 @@ the Symfony Config component treats arrays as lists by default.
373
372
In order to maintain the array keys use the ``useAttributeAsKey() `` method::
374
373
375
374
$node
376
- ->fixXmlConfig('connection')
377
375
->children()
378
- ->arrayNode('connections')
376
+ ->arrayNode('connections', 'connection' )
379
377
->useAttributeAsKey('name')
380
378
->arrayPrototype()
381
379
->children()
@@ -718,14 +716,14 @@ normalization would make both of these ``auto_connect``.
718
716
``foo-bar_moo `` or if it already exists.
719
717
720
718
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) :
722
720
723
721
.. code-block :: yaml
724
722
725
723
twig :
726
724
extensions : ['twig.extension.foo', 'twig.extension.bar']
727
725
728
- and in XML:
726
+ and in XML you have a list of options called `` extension `` (in singular) :
729
727
730
728
.. code-block :: xml
731
729
@@ -734,33 +732,24 @@ and in XML:
734
732
<twig : extension >twig.extension.bar</twig : extension >
735
733
</twig : config >
736
734
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::
740
737
741
738
$rootNode
742
- ->fixXmlConfig('extension')
743
739
->children()
744
- ->arrayNode('extensions')
740
+ ->arrayNode('extensions', 'extension' )
745
741
->scalarPrototype()->end()
746
742
->end()
747
743
->end()
748
744
;
749
745
750
- If it is an irregular pluralization you can specify the plural to use as
751
- a second argument::
746
+ .. versionadded :: 7.4
752
747
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') ``).
761
751
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:
764
753
765
754
.. code-block :: xml
766
755
@@ -775,7 +764,7 @@ and sometimes only:
775
764
776
765
By default, ``connection `` would be an array in the first case and a string
777
766
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 () ``.
779
768
780
769
You can further control the normalization process if you need to. For example,
781
770
you may want to allow a string to be set and used as a particular key or
0 commit comments