Closed aidan-casey closed 8 months ago
Hi @aidan-casey !
what you are proposing is to remove the die
block from the catch
?
try {
$dotenv = Dotenv::createUnsafeImmutable($root);
$dotenv->load();
} catch (InvalidPathException) {
die("Missing .env file in {$root}" . PHP_EOL);
}
Yup!
This is supported out of the box by the package you're using. You can do
$dotenv = Dotenv::createUnsafeImmutable($root);
$dotenv->loadSafe();
See https://github.com/vlucas/phpdotenv README.
To suppress the exception that is thrown when there is no .env file, you can use loadSafe
I thought I recalled there being a method for this. Thank you!
Just as a sidenote: what a confusing API 🙃
createUnsafeImmutable
loadSafe
We're creating unsafe immutable… what exactly? And then we're safe loading the unsafe stuff? 🤯
It is entirely valid to load environment variables from the system and will commonly done with things like Docker. I'm not sure we should be preventing the application from loading without the
.env
file.