Skip to content

Commit

Permalink
Merge branch '5.4' into 6.0
Browse files Browse the repository at this point in the history
* 5.4:
  [Messenger] Fix dealing with unexpected payload in Redis transport
  [Filesystem] Update some PHPDoc of the Path class
  [VarDumper] Fix dumping mysqli_driver instances
  Fix missing ReturnTypeWillChange attributes
  [Cache] Add missing log when saving namespace
  [HttpKernel] Reset services between requests performed by KernelBrowser
  [HttpKernel] Remove unused argument in ArgumentMetadataFactory
  [Stopwatch] Fix test expectation
  [SecurityBundle] fix autoconfiguring Monolog's ProcessorInterface
  KernelTestCase resets internal state on tearDown
  [Security/Http] Fix getting password-upgrader when user-loader is a closure
  [HttpKernel] Fix extracting controller name from closures
  [Intl] fix wrong offset timezone PHP 8.1
  Fix type binding
  Remove duplicated test
  [Dotenv] Fix reading config for symfony/runtime when running dump command
  [Serializer] Remove unnecessary break
  [Runtime] Fix dotenv_overload with commands
  Make document type nodes ignorable
  Initialize Symfony\Component\Security\Core\Exception\AccountStatusException:: property
  • Loading branch information
nicolas-grekas committed Feb 21, 2022
2 parents 3b1ee78 + 06fdd94 commit af6571d
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 7 deletions.
14 changes: 7 additions & 7 deletions SymfonyRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions Tests/phpt/dotenv_overload_command_debug_exists_0_to_1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;

$_SERVER['DEBUG_ENABLED'] = '0';
$_SERVER['APP_RUNTIME_OPTIONS'] = [
'debug_var_name' => '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']);
});
};
16 changes: 16 additions & 0 deletions Tests/phpt/dotenv_overload_command_debug_exists_0_to_1.phpt
Original file line number Diff line number Diff line change
@@ -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--
<?php

$_SERVER['argv'] = [
'my_app',
];
$_SERVER['argc'] = 1;
require $_SERVER['SCRIPT_FILENAME'] = __DIR__.'/dotenv_overload_command_debug_exists_0_to_1.php';

?>
--EXPECTF--
1
18 changes: 18 additions & 0 deletions Tests/phpt/dotenv_overload_command_debug_exists_1_to_0.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;

$_SERVER['DEBUG_MODE'] = '1';
$_SERVER['APP_RUNTIME_OPTIONS'] = [
'debug_var_name' => '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']);
});
};
16 changes: 16 additions & 0 deletions Tests/phpt/dotenv_overload_command_debug_exists_1_to_0.phpt
Original file line number Diff line number Diff line change
@@ -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--
<?php

$_SERVER['argv'] = [
'my_app',
];
$_SERVER['argc'] = 1;
require $_SERVER['SCRIPT_FILENAME'] = __DIR__.'/dotenv_overload_command_debug_exists_1_to_0.php';

?>
--EXPECTF--
0
18 changes: 18 additions & 0 deletions Tests/phpt/dotenv_overload_command_env_exists.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;

$_SERVER['ENV_MODE'] = 'notfoo';
$_SERVER['APP_RUNTIME_OPTIONS'] = [
'env_var_name' => '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']);
});
};
16 changes: 16 additions & 0 deletions Tests/phpt/dotenv_overload_command_env_exists.phpt
Original file line number Diff line number Diff line change
@@ -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--
<?php

$_SERVER['argv'] = [
'my_app',
];
$_SERVER['argc'] = 1;
require $_SERVER['SCRIPT_FILENAME'] = __DIR__.'/dotenv_overload_command_env_exists.php';

?>
--EXPECTF--
foo

0 comments on commit af6571d

Please sign in to comment.