How to access .yml options in services.yml?

Here are the options.

application /Config/parameters.yml

parameters: test: enabled: true validate: true 

And this is the service that I want to configure using the test parameter from the previous file.

MyBundle / Resources / Configurations / services.yml

 imports: - { resource: "parameters.yml" } parameters: services: my.form.type: class: My\Bundle\Form\Type\MyType arguments: - %test% 

Import does not work. How am I supposed to do this?

PS I know that I can turn to @service_container. But the point is to pass the array explicitly through yaml.

+4
source share
1 answer

you can omit ...

 imports: - { resource: "parameters.yml" } parameters: 

... parameters.yml is automatically parsed, and the parameters should be available for injection if you surround them with % .

Try:

 services: my.form.type: class: My\Bundle\Form\Type\MyType arguments: ["%test%"] alias: my_form_type 
+5
source

Source: https://habr.com/ru/post/1492692/


All Articles