Symfony2 from YAML to XML configuration

Actually i was a fan of YAML regarding the configuration files of Symfony2.
This was probably because i was used to it since symfony 1.4 and i also thought its better readable.
Its partly still true, but my Netbeans Editor has some problems with using @ in YAML and this breaks my highlighting.
So the better readability vanished to nirvana.

So i checked out XML configuration. Its also widely used by the community.
Pros and Cons (mostly Pros) you can read in this post by Fabien.

And yeah its true, these advantages from Fabiens Post i really appreciate:

  • When a XML file is loaded, it is automatically validated with the built-in services.xsd file
  • The XML can be auto-completed in IDEs;
  • The XML format is faster than the YAML one;

So here are two tips how to convert certain constructs from YAML to XML.
I had to search for that so i like to mention it.

Arrays in Parameters

YAML, services.yml:

<br />parameters:<br />  my.array: [value1,value2]<br />

XML, services.xml:

<br /><parameters><br />   <parameter key="my.array" type="collection"><br />      <parameter>value1</parameter><br />      <parameter>value2</parameter><br />   </parameter><br /></parameters><br />

Arrays are of type collection in XML. This structure also applys to Arguments.

Service References

YAML, services.yml:

<br />arguments: [@this.service.defined.before]<br />

XML, services.xml:

<br /><argument type="service" id="this.service.defined.before" /><br />

Hope it helps :)

3 Replies to “Symfony2 from YAML to XML configuration”

  1. Hey Ivo,

    very cool, I’ve been struggling a bit with xml myself, so thanks for this.

    Just wanted to point out that the Netbeans code highlighting works if you wrap the service names in quotes.

    ‘@some_service’ for example.

Leave a Reply

Your email address will not be published. Required fields are marked *