Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass nested parameter value to service in Symfony2

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?

like image 514
Victor Bocharsky Avatar asked Jan 13 '14 12:01

Victor Bocharsky


1 Answers

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%]
like image 189
maphe Avatar answered Nov 11 '22 00:11

maphe