diff --git a/src/Symfony/Component/Runtime/SymfonyRuntime.php b/src/Symfony/Component/Runtime/SymfonyRuntime.php index 52a8ce860caf2..0ca9713049545 100644 --- a/src/Symfony/Component/Runtime/SymfonyRuntime.php +++ b/src/Symfony/Component/Runtime/SymfonyRuntime.php @@ -98,24 +98,24 @@ public function __construct(array $options = []) } elseif (isset($_SERVER['argv']) && class_exists(ArgvInput::class)) { $this->options = $options; $this->getInput(); - $inputEnv = $_SERVER[$envKey] ?? null; - $inputDebug = $_SERVER[$debugKey] ?? null; } if (!($options['disable_dotenv'] ?? false) && isset($options['project_dir']) && !class_exists(MissingDotenv::class, false)) { (new Dotenv($envKey, $debugKey)) ->setProdEnvs((array) ($options['prod_envs'] ?? ['prod'])) ->usePutenv($options['use_putenv'] ?? false) - ->bootEnv($options['project_dir'].'/'.($options['dotenv_path'] ?? '.env'), 'dev', (array) ($options['test_envs'] ?? ['test']), $dotenvOverload = $options['dotenv_overload'] ?? false); - if ($dotenvOverload) { - if (isset($inputEnv) && $inputEnv !== $_SERVER[$envKey]) { + ->bootEnv($options['project_dir'].'/'.($options['dotenv_path'] ?? '.env'), 'dev', (array) ($options['test_envs'] ?? ['test']), $options['dotenv_overload'] ?? false); + + if ($this->input && ($options['dotenv_overload'] ?? false)) { + if ($this->input->getParameterOption(['--env', '-e'], $_SERVER[$envKey], true) !== $_SERVER[$envKey]) { 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)); } - if (isset($inputDebug) && $inputDebug !== $_SERVER[$debugKey]) { - putenv($debugKey.'='.$_SERVER[$debugKey] = $_ENV[$debugKey] = $inputDebug); + if ($_SERVER[$debugKey] && $this->input->hasParameterOption('--no-debug', true)) { + putenv($debugKey.'='.$_SERVER[$debugKey] = $_ENV[$debugKey] = '0'); } } + $options['debug'] ?? $options['debug'] = '1' === $_SERVER[$debugKey]; $options['disable_dotenv'] = true; } else { diff --git a/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_0_to_1.php b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_0_to_1.php new file mode 100644 index 0000000000000..a2e5f5a6cb7b7 --- /dev/null +++ b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_0_to_1.php @@ -0,0 +1,18 @@ + 'DEBUG_ENABLED', + 'dotenv_overload' => true, +]; + +require __DIR__.'/autoload.php'; + +return static function (Command $command, OutputInterface $output, array $context): Command { + return $command->setCode(static function () use ($output, $context): void { + $output->writeln($context['DEBUG_ENABLED']); + }); +}; diff --git a/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_0_to_1.phpt b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_0_to_1.phpt new file mode 100644 index 0000000000000..a5f785ae50f67 --- /dev/null +++ b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_0_to_1.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test Dotenv overload with a command when debug=0 exists and debug=1 in .env and the --no-debug option is not used +--INI-- +display_errors=1 +--FILE-- + +--EXPECTF-- +1 diff --git a/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_1_to_0.php b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_1_to_0.php new file mode 100644 index 0000000000000..bb2df9623e008 --- /dev/null +++ b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_1_to_0.php @@ -0,0 +1,18 @@ + 'DEBUG_MODE', + 'dotenv_overload' => true, +]; + +require __DIR__.'/autoload.php'; + +return static function (Command $command, OutputInterface $output, array $context): Command { + return $command->setCode(static function () use ($output, $context): void { + $output->writeln($context['DEBUG_MODE']); + }); +}; diff --git a/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_1_to_0.phpt b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_1_to_0.phpt new file mode 100644 index 0000000000000..24ff962fea51f --- /dev/null +++ b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_debug_exists_1_to_0.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test Dotenv overload with a command when debug=1 exists and debug=0 in .env and the --no-debug option is not used +--INI-- +display_errors=1 +--FILE-- + +--EXPECTF-- +0 diff --git a/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_env_exists.php b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_env_exists.php new file mode 100644 index 0000000000000..2bb359352de94 --- /dev/null +++ b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_env_exists.php @@ -0,0 +1,18 @@ + 'ENV_MODE', + 'dotenv_overload' => true, +]; + +require __DIR__.'/autoload.php'; + +return static function (Command $command, OutputInterface $output, array $context): Command { + return $command->setCode(static function () use ($output, $context): void { + $output->writeln($context['ENV_MODE']); + }); +}; diff --git a/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_env_exists.phpt b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_env_exists.phpt new file mode 100644 index 0000000000000..36c8644aaa89c --- /dev/null +++ b/src/Symfony/Component/Runtime/Tests/phpt/dotenv_overload_command_env_exists.phpt @@ -0,0 +1,16 @@ +--TEST-- +Test Dotenv overload with a command when existing env=notfoo and env=foo in .env and the --env option is not used +--INI-- +display_errors=1 +--FILE-- + +--EXPECTF-- +foo pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy