Symfony YAML 格式转换:"calls" with string params

Symfony YAML format conversion: "calls" with string params

我要转换的服务定义示例:

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

编译为:

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

根据我的问题我接下来试试:

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

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

编译为:

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

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

UPD#1

根据我之前的问题,下一个 YAML 示例也不会编译为 "add" 方法的两次调用,只有一次:

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

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

编译为:

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

您的扩展缺少 -,它应该是:

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

在您的 "rewrite" 中,两个 add 标量是同一序列的一部分,但在您的原始序列中,它们是父序列不同元素的第一个元素。

同样的问题出现在第二个例子中。