Symfony YAML format conversion: “calls” with string params

强颜欢笑 提交于 2019-12-11 06:04:22

问题


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")));

回答1:


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.



来源:https://stackoverflow.com/questions/38912122/symfony-yaml-format-conversion-calls-with-string-params

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!