diff --git a/src/Symfony/Component/Runtime/CHANGELOG.md b/src/Symfony/Component/Runtime/CHANGELOG.md index a705a84234f35..6add6187937c6 100644 --- a/src/Symfony/Component/Runtime/CHANGELOG.md +++ b/src/Symfony/Component/Runtime/CHANGELOG.md @@ -5,7 +5,7 @@ CHANGELOG --- * The component is not experimental anymore - * Add options "env_var_names" to `GenericRuntime` and `SymfonyRuntime` + * Add options "env_var_name" and "debug_var_name" to `GenericRuntime` and `SymfonyRuntime` 5.3.0 ----- diff --git a/src/Symfony/Component/Runtime/GenericRuntime.php b/src/Symfony/Component/Runtime/GenericRuntime.php index 03c8c51067069..c88832f821a77 100644 --- a/src/Symfony/Component/Runtime/GenericRuntime.php +++ b/src/Symfony/Component/Runtime/GenericRuntime.php @@ -27,7 +27,9 @@ class_exists(ClosureResolver::class); * to the "APP_DEBUG" environment variable; * - "runtimes" maps types to a GenericRuntime implementation * that knows how to deal with each of them; - * - "error_handler" defines the class to use to handle PHP errors. + * - "error_handler" defines the class to use to handle PHP errors; + * - "env_var_name" and "debug_var_name" define the name of the env + * vars that hold the Symfony env and the debug flag respectively. * * The app-callable can declare arguments among either: * - "array $context" to get a local array similar to $_SERVER; @@ -51,13 +53,14 @@ class GenericRuntime implements RuntimeInterface * debug?: ?bool, * runtimes?: ?array, * error_handler?: string|false, - * env_var_names?: ?array, + * env_var_name?: string, + * debug_var_name?: string, * } $options */ public function __construct(array $options = []) { - $options['env_var_names']['env_key'] ?? $options['env_var_names']['env_key'] = 'APP_ENV'; - $debugKey = $options['env_var_names']['debug_key'] ?? $options['env_var_names']['debug_key'] = 'APP_DEBUG'; + $options['env_var_name'] ?? $options['env_var_name'] = 'APP_ENV'; + $debugKey = $options['debug_var_name'] ?? $options['debug_var_name'] = 'APP_DEBUG'; $debug = $options['debug'] ?? $_SERVER[$debugKey] ?? $_ENV[$debugKey] ?? true; @@ -107,7 +110,7 @@ public function getResolver(callable $callable, \ReflectionFunction $reflector = return $arguments; }; - if ($_SERVER[$this->options['env_var_names']['debug_key']]) { + if ($_SERVER[$this->options['debug_var_name']]) { return new DebugClosureResolver($callable, $arguments); } @@ -139,7 +142,7 @@ public function getRunner(?object $application): RunnerInterface $application = \Closure::fromCallable($application); } - if ($_SERVER[$this->options['env_var_names']['debug_key']] && ($r = new \ReflectionFunction($application)) && $r->getNumberOfRequiredParameters()) { + if ($_SERVER[$this->options['debug_var_name']] && ($r = new \ReflectionFunction($application)) && $r->getNumberOfRequiredParameters()) { throw new \ArgumentCountError(sprintf('Zero argument should be required by the runner callable, but at least one is in "%s" on line "%d.', $r->getFileName(), $r->getStartLine())); } diff --git a/src/Symfony/Component/Runtime/SymfonyRuntime.php b/src/Symfony/Component/Runtime/SymfonyRuntime.php index 3ef4fd65f200d..fc721a2dfd450 100644 --- a/src/Symfony/Component/Runtime/SymfonyRuntime.php +++ b/src/Symfony/Component/Runtime/SymfonyRuntime.php @@ -82,13 +82,14 @@ class SymfonyRuntime extends GenericRuntime * use_putenv?: ?bool, * runtimes?: ?array, * error_handler?: string|false, - * env_var_names?: ?array, + * env_var_name?: string, + * debug_var_name?: string, * } $options */ public function __construct(array $options = []) { - $envKey = $options['env_var_names']['env_key'] ?? $options['env_var_names']['env_key'] = 'APP_ENV'; - $debugKey = $options['env_var_names']['debug_key'] ?? $options['env_var_names']['debug_key'] = 'APP_DEBUG'; + $envKey = $options['env_var_name'] ?? $options['env_var_name'] = 'APP_ENV'; + $debugKey = $options['debug_var_name'] ?? $options['debug_var_name'] = 'APP_DEBUG'; if (isset($options['env'])) { $_SERVER[$envKey] = $options['env']; @@ -144,7 +145,7 @@ public function getRunner(?object $application): RunnerInterface } set_time_limit(0); - $defaultEnv = !isset($this->options['env']) ? ($_SERVER[$this->options['env_var_names']['env_key']] ?? 'dev') : null; + $defaultEnv = !isset($this->options['env']) ? ($_SERVER[$this->options['env_var_name']] ?? 'dev') : null; $output = $this->output ?? $this->output = new ConsoleOutput(); return new ConsoleApplicationRunner($application, $defaultEnv, $this->getInput(), $output); @@ -212,11 +213,11 @@ private function getInput(): ArgvInput } if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) { - 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); + putenv($this->options['env_var_name'].'='.$_SERVER[$this->options['env_var_name']] = $_ENV[$this->options['env_var_name']] = $env); } if ($input->hasParameterOption('--no-debug', true)) { - 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'); + putenv($this->options['debug_var_name'].'='.$_SERVER[$this->options['debug_var_name']] = $_ENV[$this->options['debug_var_name']] = '0'); } return $this->input = $input;