XML到YAML的转换

时间:2014-03-26 02:16:30

标签: xml symfony yaml

我正在尝试在我的symfony项目中将此XML转换为YAML格式。遇到一些问题。

<?xml version="1.0" ?>
    <!-- src/Test/WebBundle/Resources/config/services.xml-->
    <container xmlns="http://symfony.com/schema/dic/services"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
        <parameters>
                <parameter key="adoy_oauth2.client.class">OAuth2\Client</parameter>
                <parameter key="test_web.client.class">Test\WebBundle\Service\OAuth2Client</parameter>
            </parameters>

            <services>
                <service id="adoy_oauth2.client" class="%adoy_oauth2.client.class%">
                    <argument>%oauth2_client_id%</argument>
                    <argument>%oauth2_client_secret%</argument>
                </service>

                <service id="test_web.credentials_client" class="%test_web.client.class%">
                    <argument type="service" id="adoy_oauth2.client" />
                    <argument>%oauth2_auth_endpoint%</argument>
                    <argument>%oauth2_token_endpoint%</argument>
                    <argument>%oauth2_redirect_url%</argument>
                    <argument>client_credentials</argument>
                    <argument type="collection">
                        <argument key="client_id">%oauth2_client_id%</argument>
                        <argument key="client_secret">%oauth2_client_secret%</argument>
                    </argument>
                </service>

                <service id="test_web.authorize_client" class="%test_web.client.class%">
                    <argument type="service" id="adoy_oauth2.client" />
                    <argument>%oauth2_auth_endpoint%</argument>
                    <argument>%oauth2_token_endpoint%</argument>
                    <argument>%oauth2_redirect_url%</argument>
                    <argument>authorization_code</argument>
                    <argument type="collection">
                        <argument key="redirect_uri">%oauth2_redirect_url%</argument>
                    </argument>
                </service>
            </services>
</container>

这是我试过的YAML:

parameters:
     adoy_oauth2.client.class: OAuth2\Client
     test_web.client.class: Lyke\WebBundle\Service\OAuth2Client

services:
     adoy_oauth2.client:
         class: %adoy_oauth2.client.class%
         arguments: [%oauth2_client_id%, %oauth2_client_secret%]
     test_web.credentials_client:
         test_: %lyke_web.client.class%
         arguments:
             - @adoy_oauth2.client
             - [%oauth2_auth_endpoint%, %oauth2_token_endpoint%, %oauth2_redirect_url%, "client_credentials"]
             - {
                    collection:
                    {
                        client_id: %oauth2_client_id%,
                        client_secret: %oauth2_client_secret%
                    }
               }
     test_web.authorize_client:
         test_: %lyke_web.client.class%
         arguments: 
             - @adoy_oauth2.client
             - [%oauth2_auth_endpoint%, %oauth2_token_endpoint%, %oauth2_redirect_url%, "authorization_code"]
             - {
                    collection:
                    {
                        redirect_uri: %oauth2_redirect_url%
                    }
               }

我真的不确定如何正确转换它,我认为有两个论点是不对的。请帮忙..

2 个答案:

答案 0 :(得分:1)

你的collection论证会产生问题;我尝试使用您的XML并获得YAML,它似乎在在线工具中有效,PLease尝试使用它,

parameters:
     adoy_oauth2.client.class: OAuth2\Client
     test_web.client.class: Lyke\WebBundle\Service\OAuth2Client

services:
     adoy_oauth2.client:
         class: "%adoy_oauth2.client.class%"
         arguments: ["%oauth2_client_id%", "%oauth2_client_secret%"]
     test_web.credentials_client:
         test_: "%lyke_web.client.class%"
         arguments:
             - "@adoy_oauth2.client"
             - ["%oauth2_auth_endpoint%", "%oauth2_token_endpoint%", "%oauth2_redirect_url%", "client_credentials",[client_id: "%oauth2_client_id%",client_secret: "%oauth2_client_secret%"]]
     test_web.authorize_client:
         test_: "%lyke_web.client.class%"
         arguments: 
             - "@adoy_oauth2.client"
             - ["%oauth2_auth_endpoint%", "%oauth2_token_endpoint%", "%oauth2_redirect_url%", "authorization_code",[redirect_uri: "%oauth2_redirect_url%"]]             

YAML Converteronline YAML parser表示其有效yaml

答案 1 :(得分:0)

正如@RelaXNow在问题评论中所提到的,有一个简洁的在线工具可以将Symfony XML 配置转换为 {{3} }

<强> YAML