@@ -281,9 +281,9 @@ Before defining the children of an array node, you can provide options like:
281
281
A basic prototyped array configuration can be defined as follows::
282
282
283
283
$node
284
- ->fixXmlConfig('driver')
285
284
->children()
286
- ->arrayNode('drivers')
285
+ // the arguments are the plural and singular variants of the option name
286
+ ->arrayNode('drivers', 'driver')
287
287
->scalarPrototype()->end()
288
288
->end()
289
289
->end()
@@ -312,9 +312,8 @@ The processed configuration is::
312
312
A more complex example would be to define a prototyped array with children::
313
313
314
314
$node
315
- ->fixXmlConfig('connection')
316
315
->children()
317
- ->arrayNode('connections')
316
+ ->arrayNode('connections', 'connection' )
318
317
->arrayPrototype()
319
318
->children()
320
319
->scalarNode('table')->end()
@@ -385,9 +384,8 @@ the Symfony Config component treats arrays as lists by default.
385
384
In order to maintain the array keys use the ``useAttributeAsKey() `` method::
386
385
387
386
$node
388
- ->fixXmlConfig('connection')
389
387
->children()
390
- ->arrayNode('connections')
388
+ ->arrayNode('connections', 'connection' )
391
389
->useAttributeAsKey('name')
392
390
->arrayPrototype()
393
391
->children()
@@ -734,14 +732,14 @@ normalization would make both of these ``auto_connect``.
734
732
``foo-bar_moo `` or if it already exists.
735
733
736
734
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) :
738
736
739
737
.. code-block :: yaml
740
738
741
739
twig :
742
740
extensions : ['twig.extension.foo', 'twig.extension.bar']
743
741
744
- and in XML:
742
+ and in XML you have a list of options called `` extension `` (in singular) :
745
743
746
744
.. code-block :: xml
747
745
@@ -750,33 +748,24 @@ and in XML:
750
748
<twig : extension >twig.extension.bar</twig : extension >
751
749
</twig : config >
752
750
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::
756
753
757
754
$rootNode
758
- ->fixXmlConfig('extension')
759
755
->children()
760
- ->arrayNode('extensions')
756
+ ->arrayNode('extensions', 'extension' )
761
757
->scalarPrototype()->end()
762
758
->end()
763
759
->end()
764
760
;
765
761
766
- If it is an irregular pluralization you can specify the plural to use as
767
- a second argument::
762
+ .. versionadded :: 7.4
768
763
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') ``).
777
767
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:
780
769
781
770
.. code-block :: xml
782
771
@@ -791,7 +780,7 @@ and sometimes only:
791
780
792
781
By default, ``connection `` would be an array in the first case and a string
793
782
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 () ``.
795
784
796
785
You can further control the normalization process if you need to. For example,
797
786
you may want to allow a string to be set and used as a particular key or
0 commit comments