@@ -82,26 +82,30 @@ class SymfonyRuntime extends GenericRuntime
8282 * use_putenv?: ?bool,
8383 * runtimes?: ?array,
8484 * error_handler?: string|false,
85+ * env_var_names?: ?array,
8586 * } $options
8687 */
8788 public function __construct (array $ options = [])
8889 {
90+ $ envKey = $ options ['env_var_names ' ]['env_key ' ] ?? $ options ['env_var_names ' ]['env_key ' ] = 'APP_ENV ' ;
91+ $ debugKey = $ options ['env_var_names ' ]['debug_key ' ] ?? $ options ['env_var_names ' ]['debug_key ' ] = 'APP_DEBUG ' ;
92+
8993 if (isset ($ options ['env ' ])) {
90- $ _SERVER [' APP_ENV ' ] = $ options ['env ' ];
94+ $ _SERVER [$ envKey ] = $ options ['env ' ];
9195 } elseif (isset ($ _SERVER ['argv ' ]) && class_exists (ArgvInput::class)) {
9296 $ this ->options = $ options ;
9397 $ this ->getInput ();
9498 }
9599
96100 if (!($ options ['disable_dotenv ' ] ?? false ) && isset ($ options ['project_dir ' ]) && !class_exists (MissingDotenv::class, false )) {
97- (new Dotenv ())
101+ (new Dotenv ($ envKey , $ debugKey ))
98102 ->setProdEnvs ((array ) ($ options ['prod_envs ' ] ?? ['prod ' ]))
99103 ->usePutenv ($ options ['use_putenv ' ] ?? false )
100104 ->bootEnv ($ options ['project_dir ' ].'/ ' .($ options ['dotenv_path ' ] ?? '.env ' ), 'dev ' , (array ) ($ options ['test_envs ' ] ?? ['test ' ]));
101- $ options ['debug ' ] ?? $ options ['debug ' ] = '1 ' === $ _SERVER [' APP_DEBUG ' ];
105+ $ options ['debug ' ] ?? $ options ['debug ' ] = '1 ' === $ _SERVER [$ debugKey ];
102106 $ options ['disable_dotenv ' ] = true ;
103107 } else {
104- $ _SERVER [' APP_ENV ' ] ?? $ _SERVER [' APP_ENV ' ] = 'dev ' ;
108+ $ _SERVER [$ envKey ] ?? $ _SERVER [$ envKey ] = 'dev ' ;
105109 }
106110
107111 $ options ['error_handler ' ] ?? $ options ['error_handler ' ] = SymfonyErrorHandler::class;
@@ -140,7 +144,7 @@ public function getRunner(?object $application): RunnerInterface
140144 }
141145
142146 set_time_limit (0 );
143- $ defaultEnv = !isset ($ this ->options ['env ' ]) ? ($ _SERVER [' APP_ENV ' ] ?? 'dev ' ) : null ;
147+ $ defaultEnv = !isset ($ this ->options ['env ' ]) ? ($ _SERVER [$ this -> options [ ' env_var_names ' ][ ' env_key ' ] ] ?? 'dev ' ) : null ;
144148 $ output = $ this ->output ?? $ this ->output = new ConsoleOutput ();
145149
146150 return new ConsoleApplicationRunner ($ application , $ defaultEnv , $ this ->getInput (), $ output );
@@ -208,11 +212,11 @@ private function getInput(): ArgvInput
208212 }
209213
210214 if (null !== $ env = $ input ->getParameterOption (['--env ' , '-e ' ], null , true )) {
211- putenv (' APP_ENV = ' .$ _SERVER [' APP_ENV ' ] = $ _ENV [' APP_ENV ' ] = $ env );
215+ putenv ($ this -> options [ ' env_var_names ' ][ ' env_key ' ]. ' = ' .$ _SERVER [$ this -> options [ ' env_var_names ' ][ ' env_key ' ]] = $ _ENV [$ this -> options [ ' env_var_names ' ][ ' env_key ' ] ] = $ env );
212216 }
213217
214218 if ($ input ->hasParameterOption ('--no-debug ' , true )) {
215- putenv (' APP_DEBUG = ' .$ _SERVER [' APP_DEBUG ' ] = $ _ENV [' APP_DEBUG ' ] = '0 ');
219+ putenv ($ this -> options [ ' env_var_names ' ][ ' debug_key ' ]. ' = ' .$ _SERVER [$ this -> options [ ' env_var_names ' ][ ' debug_key ' ]] = $ _ENV [$ this -> options [ ' env_var_names ' ][ ' debug_key ' ] ] = '0 ' );
216220 }
217221
218222 return $ this ->input = $ input ;
0 commit comments