Benjamin Ghenne
Benjamin Ghenne

Reputation: 111

Symfony 5 global dynamic configuration file

I'm a long time Zend Framework user (now renamed Laminas). But I decided to give a try to last Symfony version. So I just installed it in 5.1.2.

I'm facing a question regarding the multiple environments deployments. In my compay, we have :

In ZF-Laminas, we have a global.php file which is located in config directory. For those of you who are not familiar with this framework, you can override key set in global.php file by creating local.php file.

In this global file, I use to put standard configuration for my application.

For example (prod) :

'open_id' => [
   'client_id' => 1234
]

Then, I have development and staging files which car override those values for every environmenet. During the deployment, the file corresponding to the environment is copied to local.php.

Let's say staging.local.php.dist becomes local.php with :

'open_id' => [
   'client_id' => 5678
]

Which is fine because value is overriding the one from global file.

I would like the same behavior in Symfony but I don't see something similar in Symfony 5.

So far, I only found two possibilities

What do I miss ? Or is it my "zend" way of doing things that is wrong ?

Thanks.

Upvotes: 0

Views: 1361

Answers (2)

Dmitry Solovov
Dmitry Solovov

Reputation: 333

You can also create services_%env%.yaml (services_dev.yaml, services_test.yaml) files for each environment. It will allow you to define different parameters and override/define services for each environment.

Example: config/services_dev.yaml

parameters:
    hello: 'world'

Upvotes: 2

nusje2000
nusje2000

Reputation: 503

From what I understand from your post, your goal is to have different config values based on the server you are on. If this is the case, you can use environment variables (in the .env file or .env.local for server specific config). You can then use these values in your applications by binding the env var to a parameter. This parameter will then be available within the configuration by using %parameter_name% as value or within the container. You can also pas parameters to services (service definitions are handled the same way as any other config). For more information you can checkout these sources: https://symfony.com/doc/current/configuration/env_var_processors.html https://symfony.com/doc/current/configuration.html

Upvotes: 1

Related Questions