N°6934 - Symfony 6.4 - upgrade Symfony bundles to 6.4 (#580)

* Update Symfony lib to version ~6.4.0
* Update code missing return type
* Add an iTop general configuration entry to store application secret (Symfony mandatory parameter)
* Use dependency injection in ExceptionListener & UserProvider classes
This commit is contained in:
bdalsass
2023-12-05 13:56:56 +01:00
committed by GitHub
parent 863ab4560c
commit 27ce51ab07
1392 changed files with 44869 additions and 27799 deletions

View File

@@ -11,7 +11,11 @@
namespace Symfony\Component\Dotenv\Command;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Completion\CompletionInput;
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
@@ -22,13 +26,21 @@ use Symfony\Component\Dotenv\Dotenv;
*
* @author Christopher Hertel <mail@christopher-hertel.de>
*/
#[AsCommand(name: 'debug:dotenv', description: 'List all dotenv files with variables and values')]
final class DebugCommand extends Command
{
/**
* @deprecated since Symfony 6.1
*/
protected static $defaultName = 'debug:dotenv';
protected static $defaultDescription = 'Lists all dotenv files with variables and values';
private $kernelEnvironment;
private $projectDirectory;
/**
* @deprecated since Symfony 6.1
*/
protected static $defaultDescription = 'List all dotenv files with variables and values';
private string $kernelEnvironment;
private string $projectDirectory;
public function __construct(string $kernelEnvironment, string $projectDirectory)
{
@@ -38,6 +50,25 @@ final class DebugCommand extends Command
parent::__construct();
}
protected function configure(): void
{
$this
->setDefinition([
new InputArgument('filter', InputArgument::OPTIONAL, 'The name of an environment variable or a filter.', null, $this->getAvailableVars(...)),
])
->setHelp(<<<'EOT'
The <info>%command.full_name%</info> command displays all the environment variables configured by dotenv:
<info>php %command.full_name%</info>
To get specific variables, specify its full or partial name:
<info>php %command.full_name% FOO_BAR</info>
EOT
);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
@@ -50,9 +81,7 @@ final class DebugCommand extends Command
}
$envFiles = $this->getEnvFiles();
$availableFiles = array_filter($envFiles, function (string $file) {
return is_file($this->getFilePath($file));
});
$availableFiles = array_filter($envFiles, fn (string $file) => is_file($this->getFilePath($file)));
if (\in_array('.env.local.php', $availableFiles, true)) {
$io->warning('Due to existing dump file (.env.local.php) all other dotenv files are skipped.');
@@ -63,35 +92,51 @@ final class DebugCommand extends Command
}
$io->section('Scanned Files (in descending priority)');
$io->listing(array_map(static function (string $envFile) use ($availableFiles) {
return \in_array($envFile, $availableFiles, true)
? sprintf('<fg=green>✓</> %s', $envFile)
: sprintf('<fg=red></> %s', $envFile);
}, $envFiles));
$io->listing(array_map(static fn (string $envFile) => \in_array($envFile, $availableFiles, true)
? sprintf('<fg=green>✓</> %s', $envFile)
: sprintf('<fg=red></> %s', $envFile), $envFiles));
$nameFilter = $input->getArgument('filter');
$variables = $this->getVariables($availableFiles, $nameFilter);
$io->section('Variables');
$io->table(
array_merge(['Variable', 'Value'], $availableFiles),
$this->getVariables($availableFiles)
);
$io->comment('Note real values might be different between web and CLI.');
if ($variables || null === $nameFilter) {
$io->table(
array_merge(['Variable', 'Value'], $availableFiles),
$this->getVariables($availableFiles, $nameFilter)
);
$io->comment('Note that values might be different between web and CLI.');
} else {
$io->warning(sprintf('No variables match the given filter "%s".', $nameFilter));
}
return 0;
}
private function getVariables(array $envFiles): array
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
{
$vars = explode(',', $_SERVER['SYMFONY_DOTENV_VARS'] ?? '');
sort($vars);
if ($input->mustSuggestArgumentValuesFor('filter')) {
$suggestions->suggestValues($this->getAvailableVars());
}
}
private function getVariables(array $envFiles, ?string $nameFilter): array
{
$vars = $this->getAvailableVars();
$output = [];
$fileValues = [];
foreach ($vars as $var) {
if (null !== $nameFilter && 0 !== stripos($var, $nameFilter)) {
continue;
}
$realValue = $_SERVER[$var];
$varDetails = [$var, $realValue];
foreach ($envFiles as $envFile) {
$values = $fileValues[$envFile] ?? $fileValues[$envFile] = $this->loadValues($envFile);
$values = $fileValues[$envFile] ??= $this->loadValues($envFile);
$varString = $values[$var] ?? '<fg=yellow>n/a</>';
$shortenedVar = $this->getHelper('formatter')->truncate($varString, 30);
@@ -104,6 +149,14 @@ final class DebugCommand extends Command
return $output;
}
private function getAvailableVars(): array
{
$vars = explode(',', $_SERVER['SYMFONY_DOTENV_VARS'] ?? '');
sort($vars);
return $vars;
}
private function getEnvFiles(): array
{
$files = [