Skip to content

Commit

Permalink
feat(env processor): add doc/help on env var missing exception
Browse files Browse the repository at this point in the history
  • Loading branch information
94noni committed Jun 17, 2024
1 parent f58b37a commit 0a4f6f0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Symfony/Component/DependencyInjection/EnvVarProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,19 @@ public function getEnv(string $prefix, string $name, \Closure $getEnv): mixed

if (false === $env) {
if (!$this->container->hasParameter("env($name)")) {
throw new EnvNotFoundException(sprintf('Environment variable not found: "%s".', $name));
$message = sprintf('Environment variable not found: "%s".', $name);

// Symfony internal
if ('APP_SECRET' === $name) {
$message = <<<MESSAGE
Environment variable not found: "APP_SECRET" that is needed for security reason.
Define it in your .env file via `php -r 'file_put_contents(".env", "\nAPP_SECRET=" . bin2hex(random_bytes(16)), FILE_APPEND);'` or manually as a strong and secure token
or in your vault via `php bin/console secrets:set APP_SECRET --random`
Read more at https://symfony.com/doc/current/configuration.html#configuration-based-on-environment-variables
MESSAGE;
}

throw new EnvNotFoundException($message);
}

$env = $this->container->getParameter("env($name)");
Expand Down

0 comments on commit 0a4f6f0

Please sign in to comment.