mirror of
https://github.com/symfony/recipes.git
synced 2026-09-11 15:16:30 +03:00
Add checks for Dotenv before calling it
`composer install --no-dev` fails when Dotenv is a dev dependency (which it is in skeleton) and you're running in an environment without an APP_ENV variable set. Throw exception when no env variables are set and Dotenv is absent so the user knows to either require DotEnv or specify an APP_ENV variable.
This commit is contained in:
@@ -4,5 +4,8 @@ use Symfony\Component\Dotenv\Dotenv;
|
||||
|
||||
// The check is to ensure we don't use .env in production
|
||||
if (!isset($_SERVER['APP_ENV'])) {
|
||||
if (!class_exists(Dotenv::class)) {
|
||||
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
|
||||
}
|
||||
(new Dotenv())->load(__DIR__.'/../../.env');
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ if (!class_exists(Application::class)) {
|
||||
}
|
||||
|
||||
if (!isset($_SERVER['APP_ENV'])) {
|
||||
if (!class_exists(Dotenv::class)) {
|
||||
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
|
||||
}
|
||||
(new Dotenv())->load(__DIR__.'/../.env');
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@ require __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
// The check is to ensure we don't use .env in production
|
||||
if (!isset($_SERVER['APP_ENV'])) {
|
||||
if (!class_exists(Dotenv::class)) {
|
||||
throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
|
||||
}
|
||||
(new Dotenv())->load(__DIR__.'/../.env');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user