From 88203b158e388b43b94501b841bdb07e83e373d6 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 24 Oct 2023 15:31:02 +0200 Subject: [PATCH] [DotEnv] Mention the `overrideExistingVars` parameter of `DotEnv` --- configuration.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/configuration.rst b/configuration.rst index 35417a8dfee..dd1b6f3e472 100644 --- a/configuration.rst +++ b/configuration.rst @@ -872,6 +872,27 @@ the env files ending in ``.local`` (``.env.local`` and ``.env..loca **should not be committed** because only you will use them. In fact, the ``.gitignore`` file that comes with Symfony prevents them from being committed. +Overriding Environment Values Defined By The System +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You may need to override an environment value defined by the system. This can +be done thanks to the :class:`Symfony\\Component\\Dotenv\\Dotenv` class. The +:method:`Symfony\\Component\\Dotenv\\Dotenv::loadEnv`, +:method:`Symfony\\Component\\Dotenv\\Dotenv::bootEnv`, and +:method:`Symfony\\Component\\Dotenv\\Dotenv::populate` methods accept an optional +``overrideExistingVars`` parameter that allows you to override existing environment +variables set by the system:: + + use Symfony\Component\Dotenv\Dotenv; + + $dotenv = new Dotenv(); + $dotenv->loadEnv(__DIR__.'/.env', null, 'dev', ['test'], true); + + // ... + +This will override environment variables defined by the system +and **won't** override environment variables defined in ``.env`` files. + .. _configuration-env-var-in-prod: Configuring Environment Variables in Production