symfony - Injecting other service's parameters in my own service -


I would like to know if it is possible to inject service criteria in my service and if so, how?

I should put you in context I am using FOSFacebookBundle which loads some configuration from the config.yml file. Those configuration settings (such as my Facebook app_id , secret , cookies , etc.) are kept FOSFacebookBundle this code With the following:

  // FOS \ FacebookBundle \ DependencyInjection \ FOSFacebookExtension.php foreach (array ('file', 'APIID', 'secret', 'cookie', 'domain' , 'Culture', 'permissions')) $ $ containerbuilder- & gt; Setpalmator ('fb_bookbook $ $ $ attribute, $ config [$ attribute]); }   

I know that by doing this it is possible to get those parameters through the $ container :

  $ Container-> GetParameter ('fos_facebook.app_id');   

But I would like to know if it is possible to take those parameters directly into my service definition, I have a service named FacebookHelper for which this information will be required. So I would like to do something like this:

  acme.helper.facebook: class: Application \ AcmeBundle \ Helper \ FacebookHelper argument: entityManager: "@ doctrine.orm.entity_manager" facebook: "@ Fos_facebook. Api "facebook attributes: -" @ fos_facebook.app_id "-" @ fos_facebook.secret "-" @ fos_facebook.cookie "  

Of course, this syntax does not work because the symphony is Fos_facebook.app_id The name is looking for service that does not exist.

I am looking for a solution that should avoid injecting the container directly into my service, either by direct definition of my services.yml file or your bundle Get the FOSFacebookBundle parameter from the KD extension, which will do some work to define my custom service, and inject them into it.

Regards, Matte

In fact, it's really easy And I feel that I did not think about it before posting my question that I feel ashamed. I knew how to use the parameters in the config.yml file (for example,% using locale%) but I would like to use this syntax to inject the parameter into my service definition Not thought in

In my service the FOSFacebookBundle parameters are injected:

  acme.helper.facebook: class: Application \ AcmeBundle \ Helper \ FacebookHelper logic : EntityManager: "@ doctrine.orm.entity_manager" facebook: "@ fos_facebook.api" FacebookAttup: APID: "% fos_facebook.app_id%" secret: "% fos_facebook.secret%" permissions: "% fos_facebook.permissions%"   

So Simple :) Hope this will help anyone else.

Regards,
Matt

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -