0

How can I convert this file to XML ?

services:
IHQS.nuitblanche.admin.news:
class: IHQS\NuitBlancheBundle\Admin\NewsAdmin
tags:
- { name: sonata.admin, manager_type: orm, group: nuitblanche, label: News }
arguments: [null, IHQS\NuitBlancheBundle\Entity\News, IHQSNuitBlancheBundle:NewsAdmin]

Especially for the tags part

Is :

<service id="nb.admin.news" class="IHQS\NuitBlancheBundle\Admin\NewsAdmin">
            <tag name="sonata.admin" manager_type="orm" group="NuitBlanche" label="News" />
            <argument />
            <argument>IHQS\NuitBlancheBundle\Entity\News</argument>
            <argument>IHQSNuitBlancheBundle:Admin</argument>
</service>

Correct or?

j0k
  • 22,600
  • 28
  • 79
  • 90
Julien
  • 21
  • 3
  • Have you seen [How to convert symfony yaml config files to xml format](http://stackoverflow.com/questions/6942272/how-to-convert-symfony-yaml-config-files-to-xml-format)? And can't you say it's correct or not by testing? – hakre Feb 07 '13 at 14:01

2 Answers2

0

With some help from str_replace or preg_replace you should be able to break your input text into (multidimensional) array which would be much easier to convert to XML

$example => array(
    'services' => array(
        'IHQS.nuitblanche.admin.news' => array(
            'class' => 'IHQS\NuitBlancheBundle\Admin\NewsAdmin',
            'tags' => array(
                'name' => 'sonata.admin',
                'manager_type' => 'orm',
                'group' => 'nuitblanche',
                'label' => 'News'
            ),
            arguments => array(
                null,
                'IHQS\NuitBlancheBundle\Entity\News',
                'IHQSNuitBlancheBundle:NewsAdmin'
            )
        )
    )
);
Mike
  • 1,158
  • 5
  • 22
  • 32
  • Ok thanks, but now what should i do with that? Should i use a tool that will convert it for me or do it by myself? – Julien Feb 07 '13 at 13:57
0

You don't need to convert it, you can just create the XML file and include your YAML file:

<container xmlns="http://symfony-project.org/2.0/container">
  <imports>
    <import resource="default.yml" class="sfServiceContainerLoaderFileYaml" />
  </imports>
</container>

This should also get you started to then override the settings so you can easily transpose your YAML into XML:

<container xmlns="http://symfony-project.org/2.0/container">
  <imports>
    <import resource="default.xml" />
  </imports>
  <parameters>
    <!-- These parameters override the one defined in default.xml -->
  </parameters>
  <services>
    <!-- These service definitions override the one defined in default.xml -->
  </services>
</container>

This is part of the blog post series, namely:

The component itself is documented here:

Using a similar example XML for some example YAML:

# app/config/config.yml
services:
    my_mailer:
        class:        Acme\HelloBundle\Mailer
        arguments:    [sendmail]

In XML:

<!-- app/config/config.xml -->
<services>
    <service id="my_mailer" class="Acme\HelloBundle\Mailer">
        <argument>sendmail</argument>
    </service>
</services>
hakre
  • 193,403
  • 52
  • 435
  • 836