@@ -41,6 +41,7 @@ class_exists(MissingDotenv::class, false) || class_exists(Dotenv::class) || clas
41
41
* - "test_envs" to define the names of the test envs - defaults to ["test"];
42
42
* - "use_putenv" to tell Dotenv to set env vars using putenv() (NOT RECOMMENDED.)
43
43
* - "dotenv_overload" to tell Dotenv to override existing vars
44
+ * - "dotenv_extra_paths" to define a list of additional dot-env files
44
45
*
45
46
* When the "debug" / "env" options are not defined, they will fallback to the
46
47
* "APP_DEBUG" / "APP_ENV" environment variables, and to the "--env|-e" / "--no-debug"
@@ -86,6 +87,7 @@ class SymfonyRuntime extends GenericRuntime
86
87
* env_var_name?: string,
87
88
* debug_var_name?: string,
88
89
* dotenv_overload?: ?bool,
90
+ * dotenv_extra_paths?: ?string[],
89
91
* } $options
90
92
*/
91
93
public function __construct (array $ options = [])
@@ -107,12 +109,22 @@ public function __construct(array $options = [])
107
109
}
108
110
109
111
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 ))
111
114
->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 );
114
116
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 ) {
116
128
if ($ this ->input ->getParameterOption (['--env ' , '-e ' ], $ _SERVER [$ envKey ], true ) !== $ _SERVER [$ envKey ]) {
117
129
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 ));
118
130
}
0 commit comments