@@ -41,6 +41,7 @@ class_exists(MissingDotenv::class, false) || class_exists(Dotenv::class) || clas
4141 * - "test_envs" to define the names of the test envs - defaults to ["test"];
4242 * - "use_putenv" to tell Dotenv to set env vars using putenv() (NOT RECOMMENDED.)
4343 * - "dotenv_overload" to tell Dotenv to override existing vars
44+ * - "dotenv_extra_paths" to define a list of additional dot-env files
4445 *
4546 * When the "debug" / "env" options are not defined, they will fallback to the
4647 * "APP_DEBUG" / "APP_ENV" environment variables, and to the "--env|-e" / "--no-debug"
@@ -86,6 +87,7 @@ class SymfonyRuntime extends GenericRuntime
8687 * env_var_name?: string,
8788 * debug_var_name?: string,
8889 * dotenv_overload?: ?bool,
90+ * dotenv_extra_paths?: ?string[],
8991 * } $options
9092 */
9193 public function __construct (array $ options = [])
@@ -107,12 +109,22 @@ public function __construct(array $options = [])
107109 }
108110
109111 if (!($ options ['disable_dotenv ' ] ?? false ) && isset ($ options ['project_dir ' ]) && !class_exists (MissingDotenv::class, false )) {
110- (new Dotenv ($ envKey , $ debugKey ))
112+ $ overrideExistingVars = $ options ['dotenv_overload ' ] ?? false ;
113+ $ dotenv = (new Dotenv ($ envKey , $ debugKey ))
111114 ->setProdEnvs ((array ) ($ options ['prod_envs ' ] ?? ['prod ' ]))
112- ->usePutenv ($ options ['use_putenv ' ] ?? false )
113- ->bootEnv ($ options ['project_dir ' ].'/ ' .($ options ['dotenv_path ' ] ?? '.env ' ), 'dev ' , (array ) ($ options ['test_envs ' ] ?? ['test ' ]), $ options ['dotenv_overload ' ] ?? false );
115+ ->usePutenv ($ options ['use_putenv ' ] ?? false );
114116
115- if (isset ($ this ->input ) && ($ options ['dotenv_overload ' ] ?? false )) {
117+ $ dotenv ->bootEnv ($ options ['project_dir ' ].'/ ' .($ options ['dotenv_path ' ] ?? '.env ' ), 'dev ' , (array ) ($ options ['test_envs ' ] ?? ['test ' ]), $ overrideExistingVars );
118+
119+ if (\is_array ($ options ['dotenv_extra_paths ' ] ?? null ) && $ options ['dotenv_extra_paths ' ]) {
120+ $ options ['dotenv_extra_paths ' ] = array_map (fn (string $ path ) => $ options ['project_dir ' ].'/ ' .$ path , $ options ['dotenv_extra_paths ' ]);
121+
122+ $ overrideExistingVars
123+ ? $ dotenv ->overload (...$ options ['dotenv_extra_paths ' ])
124+ : $ dotenv ->load (...$ options ['dotenv_extra_paths ' ]);
125+ }
126+
127+ if (isset ($ this ->input ) && $ overrideExistingVars ) {
116128 if ($ this ->input ->getParameterOption (['--env ' , '-e ' ], $ _SERVER [$ envKey ], true ) !== $ _SERVER [$ envKey ]) {
117129 throw new \LogicException (\sprintf ('Cannot use "--env" or "-e" when the "%s" file defines "%s" and the "dotenv_overload" runtime option is true. ' , $ options ['dotenv_path ' ] ?? '.env ' , $ envKey ));
118130 }
0 commit comments