Symfony2: How to inject ALL parameters in a service?

后端 未结 7 853
既然无缘
既然无缘 2020-12-28 14:14

How can I inject ALL parameters in a service?

I know I can do: arguments: [%some.key%] which will pass the parameters: some.key: \"value\"

7条回答
  •  既然无缘
    2020-12-28 15:06

    Suggestion to define a service at services.yml, which will inject the parameterBag and allow access to any of your parameter

    service.container_parameters:
      public: false
      class: stdClass
      factory_service: service_container
      factory_method: getParameterBag
    

    Inject your service, and u can get your parameter using below

    $parameterService->get('some.key');
    

提交回复
热议问题