1

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")));
Community
  • 1
  • 1
Alex
  • 571
  • 1
  • 8
  • 26

1 Answers1

2

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.

Anthon
  • 69,918
  • 32
  • 186
  • 246
  • Hmm, i already tried to add missed "-" as you suggest. Add it again now - and it works o_O. Magic. Or cache. The same with second example with @service - also workerd now. – Alex Aug 12 '16 at 07:37
  • Maybe a good idea to keep two windows open to http://yaml-online-parser.appspot.com, one with the original and one with the rewrite (at least while you are experimenting). If the corresponding JSON has differences (which you should be able to notice easily), your input YAML has semantic differences. – Anthon Aug 12 '16 at 10:43