Search code examples
phpsymfony4php-7.3symfony-4.3

Multiple security configs for one project


How is possible to load a specific security config regarding Env variable.

security:
        providers:
            #### if getenv(PROJECT) === EXTERNAL
            users:
                entity:
                    class: App\Entity\UserRegister
            #### endOnly For external
            #### if getenv(PROJECT) === INTERNAL
            my_ldap:
                ldap:
                    ...
            #### endOnly for internal

My Goal is to use the LDAP for internal project and Database Provider for the external one


Solution

  • Probably the best solution for symfony is to use different environments.

    There are already dev, prod and test environment in your project, so just add new internal one.

    If there is only one setting to change you can import others:

    imports:
        - { resource: '../dev/' }