Victor Bocharsky
Victor Bocharsky

Reputation: 12306

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?

Upvotes: 6

Views: 2626

Answers (1)

maphe
maphe

Reputation: 1931

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%]

Upvotes: 2

Related Questions