Symfony documentation recommends to use XML for dependency injection configuration. I like the yml format because its simple and intuitive, but the main benefit of XML is the possibility for better validation and editing help.
So today we tried to port some configuration from yaml to xml.
Our yaml file contained an array parameter:
parameters:
symfony_cmf_multilang_content.lang_preference:
en: [en, de]
de: [de, en]
To make this work in XML, you need to nest parameter tags and use the type="collection" attribute.
<parameters>
<parameter key="symfony_cmf_multilang_content.lang_preference" type="collection">
<parameter key="en" type="collection">
<parameter>en</parameter>
<parameter>de</parameter>
</parameter>
<parameter key="de" type="collection">
<parameter>de</parameter>
<parameter>en</parameter>
</parameter>
</parameter>
</parameters>
If you forget the type="collection" attribute, your parameter will contain whitespace from between the xml tags, but no content. You will probably just get some random error somewhere about things not being an array. (That is, if you do not validate your configuration. If you do, you will get errors in the validation so at least you will be closer to the place of the problem.)
Comments
symfony doc
just a short notice: this information is now part of the official symfony doc too:
http://symfony.com/doc/current/book/service_container.html#array-parameters
wondering
you spoke of validation configuration xml, how is that done? or how did you do it?
thanks
configuration validation
i do not validate with an xml schema myself, but maybe this cookbook entry helps you: http://symfony.com/doc/2.0/cookbook/bundles/extension.html