Symfony YAML格式转换:“调用”与字符串参数 [英] Symfony YAML format conversion: "calls" with string params

查看:117
本文介绍了Symfony YAML格式转换:“调用”与字符串参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

服务定义示例我想转换:

  MyService:
class:MyClass
calls:
- [add,[%param1%,%param2%]]
- [add,[%param3%,%param4%]]

此编译为:

  $ instance-> add('param1','param2'); 
$ instance-> add('param3','param4');

根据我的问题#38822898 我试试看:

  MyService:
class :MyClass
调用:
-
- 添加
-
- %param1%
- %param2%

- 添加
-
- %param3%
- %param4%

$ b $
$ b



  $ instance-> add('param1','param2 ); 

那么,第二个YAML例子中的问题在哪里?



UPD#1

根据我以前的问题,下一个YAML例子也不会编译成两个add 方法,只有一个:

  MyAnotherService:
class:MyAnotherClass
factory:
- MyFactoryClass
- 创建
调用:
-
- 添加
-
- > -
@ = service('AnotherService1')。创建(
服务('AnotherService2'),
服务('AnotherService3')


- 添加
-
- > -
@ = service('AnotherService1')。create(
service('AnotherService3'),
service('AnotherService4')

编译到:

  $ instance-> add($ this-> get(AnotherService1) - > create($ this-> get(AnotherService2),$ this-> get AnotherService3\" ))); 


解决方案

- ,应该是:

$ p $ MyService:
class:MyClass
调用:
-
- add
-
- %param1%
- %param2%
- #<这个缺少
- 加
-
- %param3%
- %param4%
$ b $在你的重写中,两个 add 标量是同一个序列的一部分,但是在你的原始版本中,它们是第一个元素的父元素不同。



同样的问题发生在第二个例子中。


Service definition example I want to convert:

MyService:
    class: MyClass
    calls:
        - [add, ["%param1%", "%param2%"]]
        - [add, ["%param3%", "%param4%"]]

And this compile to:

$instance->add('param1', 'param2');
$instance->add('param3', 'param4');

According to my question #38822898 I try next:

MyService:
    class: MyClass
    calls:
        -
            - add
            -
                - "%param1%"
                - "%param2%"

            - add
            -
                - "%param3%"
                - "%param4%"

And this compile to:

$instance->add('param1', 'param2');

So, where is the problem in second YAML example?

UPD#1

According to my previous question, the next YAML example also do not compile to two calls of "add" method, only one:

MyAnotherService:
    class: MyAnotherClass
    factory:
        - MyFactoryClass
        - create
    calls:
        -
            - add
            -
                - >-
                    @=service('AnotherService1').create(
                        service('AnotherService2'),
                        service('AnotherService3')
                    )

            - add
            -
                - >-
                    @=service('AnotherService1').create(
                        service('AnotherService3'),
                        service('AnotherService4')
                    )

Compiles to:

$instance->add($this->get("AnotherService1")->create($this->get("AnotherService2"), $this->get("AnotherService3")));

解决方案

Your expansion is missing a -, it should be:

MyService:
    class: MyClass
    calls:
        -
            - add
            -
                - "%param1%"
                - "%param2%"
        -            # < this one is missing
            - add
            -
                - "%param3%"
                - "%param4%"

In your "rewrite" the two add scalars are part of the same sequence, but in your original they are the first elements of different elements of the parent sequence.

The same problem occurs with the second example.

这篇关于Symfony YAML格式转换:“调用”与字符串参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆