0
votes

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 :

  • Local environment which is developer pc.
  • Development.
  • Staging.
  • Production.

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

  • Create a bundle which will allow me to have a <bundle_name>.yaml file in config/packages directory. According to the documentation (https://symfony.com/doc/current/configuration.html#configuration-files), I will be able to have dev, prod and staging overrides. But it forces me to create a bundle to handle just some standard configurations, which is huge.

  • Use .env files. But .env files only allow string data, not complex data like arrays.

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

Thanks.

2

2 Answers

2
votes

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'
1
votes

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