How can I pass nested parameter value to service i

2019-06-18 15:34发布

For example, in my services.yml file next code:

parameters:
    social:
        facebook:
            app_id: 123456789
            secret: dkl41a5dw1daw11d1wa135451awwlflaw
        google:
            id: 12548411654

services:
    bw.user.social:
        class: BW\UserBundle\Service\SocialService
        arguments: [%social.facebook%]

This method does not work. I can use this:

services:
    bw.user.social:
        class: BW\UserBundle\Service\SocialService
        arguments: [%social%]

But it's not exactly what I need. How can I pass only facebook value without google and , it's very important, not change parameters structure?

1条回答
贼婆χ
2楼-- · 2019-06-18 15:51

You have to write your parameters like this :

parameters:
    social.facebook:
        app_id: 123456789
        secret: dkl41a5dw1daw11d1wa135451awwlflaw
    social.google:
        id: 12548411654

Then you can use :

services:
    bw.user.social:
        class: BW\UserBundle\Service\SocialService
        arguments: [%social.facebook%]
查看更多
登录 后发表回答