Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony4 - opt out of the "environment variables" feature and keep the old parameters.yml file?

In Symfony4 they chose to replace the parameters.yml with environment variables, as said in the docs and in the migration guides:

Define the infrastructure-related configuration options as environment variables. During development, use the .env file at the root of your project to set these.

I really don't like this change, I don't see any advantage but only drawbacks (for example we'd need to refactor the app because now only scalar values are allowed as environment variables, you can't host different installations in the same environment, etc...)

So my question is, is it possible to keep the old good parameters.yml file in Symfony4? How can I include this file and refer to his parameters, for example, in the doctrine.yml and swiftmailer.yml?

like image 743
the_nuts Avatar asked Jan 21 '18 00:01

the_nuts


1 Answers

Done, it's very easy and it makes your migration to Symfony4 much easier.

Just move the parameters.yml and parameters.yml.dist to config/, and rename them to .yaml for consistency.

Then add in services.yaml:

imports:
    - { resource: parameters.yaml }

Then everything will remain the same, for example the doctrine.yaml file will be:

doctrine:
    dbal:
        driver: 'pdo_mysql'
        server_version: '5.7'
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        ...

Optional: add https://github.com/Incenteev/ParameterHandler

like image 100
the_nuts Avatar answered Nov 17 '22 07:11

the_nuts