0

如何将此文件转换为 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]

特别是对于标签部分

是 :

<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>

对还是?

4

2 回答 2

0

在 str_replace 或 preg_replace 的帮助下,您应该能够将输入文本分解为(多维)数组,这将更容易转换为 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'
            )
        )
    )
);
于 2013-02-07T13:37:45.360 回答
0

您不需要转换它,您只需创建 XML 文件并包含您的 YAML 文件:

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

这也应该让您开始覆盖设置,以便您可以轻松地将 YAML 转换为 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>

这是博客文章系列的一部分,即:

组件本身记录在此处:

对一些示例 YAML 使用类似的示例 XML:

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

在 XML 中:

<!-- app/config/config.xml -->
<services>
    <service id="my_mailer" class="Acme\HelloBundle\Mailer">
        <argument>sendmail</argument>
    </service>
</services>
于 2013-02-07T14:06:49.307 回答