From b3c5ff1df59af0f3b56e36635385a83f286b8e3e Mon Sep 17 00:00:00 2001 From: Ben Scott Date: Fri, 10 Nov 2017 16:28:41 +0000 Subject: [PATCH] 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. --- behat/symfony2-extension/2.1/features/bootstrap/bootstrap.php | 3 +++ symfony/console/3.3/bin/console | 3 +++ symfony/framework-bundle/3.3/public/index.php | 3 +++ 3 files changed, 9 insertions(+) diff --git a/behat/symfony2-extension/2.1/features/bootstrap/bootstrap.php b/behat/symfony2-extension/2.1/features/bootstrap/bootstrap.php index f215631d..3dd50381 100644 --- a/behat/symfony2-extension/2.1/features/bootstrap/bootstrap.php +++ b/behat/symfony2-extension/2.1/features/bootstrap/bootstrap.php @@ -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'); } diff --git a/symfony/console/3.3/bin/console b/symfony/console/3.3/bin/console index 9f0dd4ea..d026a6d2 100755 --- a/symfony/console/3.3/bin/console +++ b/symfony/console/3.3/bin/console @@ -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'); } diff --git a/symfony/framework-bundle/3.3/public/index.php b/symfony/framework-bundle/3.3/public/index.php index d5255812..3c7ed08f 100644 --- a/symfony/framework-bundle/3.3/public/index.php +++ b/symfony/framework-bundle/3.3/public/index.php @@ -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'); }