This commit is contained in:
Nicolas Grekas
2025-07-10 09:12:18 +02:00
parent 1ac5e7e7e8
commit 234b6c602f
5 changed files with 19 additions and 19 deletions

View File

@@ -85,7 +85,7 @@ EOT
$dotenvPath = $this->projectDirectory;
if (is_file($composerFile = $this->projectDirectory.'/composer.json')) {
$runtimeConfig = (json_decode(file_get_contents($composerFile), true))['extra']['runtime'] ?? [];
$runtimeConfig = json_decode(file_get_contents($composerFile), true)['extra']['runtime'] ?? [];
if (isset($runtimeConfig['dotenv_path'])) {
$dotenvPath = $this->projectDirectory.'/'.$runtimeConfig['dotenv_path'];
@@ -98,18 +98,18 @@ EOT
$envFiles = $this->getEnvFiles($filePath);
$availableFiles = array_filter($envFiles, 'is_file');
if (\in_array(sprintf('%s.local.php', $filePath), $availableFiles, true)) {
$io->warning(sprintf('Due to existing dump file (%s.local.php) all other dotenv files are skipped.', $this->getRelativeName($filePath)));
if (\in_array(\sprintf('%s.local.php', $filePath), $availableFiles, true)) {
$io->warning(\sprintf('Due to existing dump file (%s.local.php) all other dotenv files are skipped.', $this->getRelativeName($filePath)));
}
if (is_file($filePath) && is_file(sprintf('%s.dist', $filePath))) {
$io->warning(sprintf('The file %s.dist gets skipped due to the existence of %1$s.', $this->getRelativeName($filePath)));
if (is_file($filePath) && is_file(\sprintf('%s.dist', $filePath))) {
$io->warning(\sprintf('The file %s.dist gets skipped due to the existence of %1$s.', $this->getRelativeName($filePath)));
}
$io->section('Scanned Files (in descending priority)');
$io->listing(array_map(fn (string $envFile) => \in_array($envFile, $availableFiles, true)
? sprintf('<fg=green>✓</> %s', $this->getRelativeName($envFile))
: sprintf('<fg=red></> %s', $this->getRelativeName($envFile)), $envFiles));
? \sprintf('<fg=green>✓</> %s', $this->getRelativeName($envFile))
: \sprintf('<fg=red></> %s', $this->getRelativeName($envFile)), $envFiles));
$nameFilter = $input->getArgument('filter');
$variables = $this->getVariables($availableFiles, $nameFilter);
@@ -124,7 +124,7 @@ EOT
$io->comment('Note that values might be different between web and CLI.');
} else {
$io->warning(sprintf('No variables match the given filter "%s".', $nameFilter));
$io->warning(\sprintf('No variables match the given filter "%s".', $nameFilter));
}
return 0;
@@ -188,17 +188,17 @@ EOT
private function getEnvFiles(string $filePath): array
{
$files = [
sprintf('%s.local.php', $filePath),
sprintf('%s.%s.local', $filePath, $this->kernelEnvironment),
sprintf('%s.%s', $filePath, $this->kernelEnvironment),
\sprintf('%s.local.php', $filePath),
\sprintf('%s.%s.local', $filePath, $this->kernelEnvironment),
\sprintf('%s.%s', $filePath, $this->kernelEnvironment),
];
if ('test' !== $this->kernelEnvironment) {
$files[] = sprintf('%s.local', $filePath);
$files[] = \sprintf('%s.local', $filePath);
}
if (!is_file($filePath) && is_file(sprintf('%s.dist', $filePath))) {
$files[] = sprintf('%s.dist', $filePath);
if (!is_file($filePath) && is_file(\sprintf('%s.dist', $filePath))) {
$files[] = \sprintf('%s.dist', $filePath);
} else {
$files[] = $filePath;
}

View File

@@ -88,7 +88,7 @@ return $vars;
EOF;
file_put_contents($dotenvPath.'.local.php', $vars, \LOCK_EX);
$output->writeln(sprintf('Successfully dumped .env files in <info>.env.local.php</> for the <info>%s</> environment.', $env));
$output->writeln(\sprintf('Successfully dumped .env files in <info>.env.local.php</> for the <info>%s</> environment.', $env));
return 0;
}

View File

@@ -460,7 +460,7 @@ final class Dotenv
try {
$process->mustRun();
} catch (ProcessException) {
throw $this->createFormatException(sprintf('Issue expanding a command (%s)', $process->getErrorOutput()));
throw $this->createFormatException(\sprintf('Issue expanding a command (%s)', $process->getErrorOutput()));
}
return preg_replace('/[\r\n]+$/', '', $process->getOutput());
@@ -515,7 +515,7 @@ final class Dotenv
if ('' === $value && isset($matches['default_value']) && '' !== $matches['default_value']) {
$unsupportedChars = strpbrk($matches['default_value'], '\'"{$');
if (false !== $unsupportedChars) {
throw $this->createFormatException(sprintf('Unsupported character "%s" found in the default value of variable "$%s".', $unsupportedChars[0], $name));
throw $this->createFormatException(\sprintf('Unsupported character "%s" found in the default value of variable "$%s".', $unsupportedChars[0], $name));
}
$value = substr($matches['default_value'], 2);

View File

@@ -24,7 +24,7 @@ final class FormatException extends \LogicException implements ExceptionInterfac
{
$this->context = $context;
parent::__construct(sprintf("%s in \"%s\" at line %d.\n%s", $message, $context->getPath(), $context->getLineno(), $context->getDetails()), $code, $previous);
parent::__construct(\sprintf("%s in \"%s\" at line %d.\n%s", $message, $context->getPath(), $context->getLineno(), $context->getDetails()), $code, $previous);
}
public function getContext(): FormatExceptionContext

View File

@@ -20,6 +20,6 @@ final class PathException extends \RuntimeException implements ExceptionInterfac
{
public function __construct(string $path, int $code = 0, ?\Throwable $previous = null)
{
parent::__construct(sprintf('Unable to read the "%s" environment file.', $path), $code, $previous);
parent::__construct(\sprintf('Unable to read the "%s" environment file.', $path), $code, $previous);
}
}