diff --git a/symfony/console/3.3/bin/console b/symfony/console/3.3/bin/console index d61dbc38b..52fd3989f 100755 --- a/symfony/console/3.3/bin/console +++ b/symfony/console/3.3/bin/console @@ -15,10 +15,8 @@ if (!class_exists(Application::class)) { } $input = new ArgvInput(); -if (null !== $_ENV['APP_ENV'] = $input->getParameterOption(['--env', '-e'], null, true)) { - putenv('APP_ENV='.$_ENV['APP_ENV']); - // force loading .env files when --env is defined - $_SERVER['APP_ENV'] = null; +if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) { + putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env); } if ($input->hasParameterOption('--no-debug', true)) { diff --git a/symfony/flex/1.0/.env b/symfony/flex/1.0/.env index 3e92b0d9b..2298d266c 100644 --- a/symfony/flex/1.0/.env +++ b/symfony/flex/1.0/.env @@ -1,5 +1,14 @@ -# This file defines all environment variables that the application needs. -# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE. -# Use ".env.local" for local overrides during development. -# Use real environment variables when deploying to production. +# In all environments, the following files are loaded if they exist, +# the later taking precedence over the former: +# +# * .env contains default values for the environment variables needed by the app +# * .env.local uncommitted file with local overrides +# * .env.$APP_ENV committed environment-specific defaults +# * .env.$APP_ENV.local uncommitted environment-specific overrides +# +# Real environment variables win over .env files. +# +# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES. +# +# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2). # https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration diff --git a/symfony/framework-bundle/3.3/config/bootstrap.php b/symfony/framework-bundle/3.3/config/bootstrap.php index 8fc9ae973..dfc5ea0fe 100644 --- a/symfony/framework-bundle/3.3/config/bootstrap.php +++ b/symfony/framework-bundle/3.3/config/bootstrap.php @@ -4,18 +4,18 @@ require dirname(__DIR__).'/vendor/autoload.php'; -if (!array_key_exists('APP_ENV', $_SERVER)) { - $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] ?? null; -} - -if ('prod' !== $_SERVER['APP_ENV']) { - if (!class_exists(Dotenv::class)) { - throw new RuntimeException('The "APP_ENV" environment variable is not set to "prod". Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.'); - } - +// Load cached env vars if the .env.local.php file exists +// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2) +if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) { + $_SERVER += $env; + $_ENV += $env; +} elseif (!class_exists(Dotenv::class)) { + throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.'); +} else { $path = dirname(__DIR__).'/.env'; $dotenv = new Dotenv(); + // load all the .env files if (method_exists($dotenv, 'loadEnv')) { $dotenv->loadEnv($path); } else { diff --git a/symfony/framework-bundle/3.3/manifest.json b/symfony/framework-bundle/3.3/manifest.json index ad7fd41a9..ea46c0b02 100644 --- a/symfony/framework-bundle/3.3/manifest.json +++ b/symfony/framework-bundle/3.3/manifest.json @@ -19,6 +19,7 @@ }, "gitignore": [ "/.env.local", + "/.env.local.php", "/.env.*.local", "/%PUBLIC_DIR%/bundles/", "/%VAR_DIR%/", diff --git a/symfony/framework-bundle/4.2/config/bootstrap.php b/symfony/framework-bundle/4.2/config/bootstrap.php index 95c1cd41a..f423c550c 100644 --- a/symfony/framework-bundle/4.2/config/bootstrap.php +++ b/symfony/framework-bundle/4.2/config/bootstrap.php @@ -4,15 +4,15 @@ require dirname(__DIR__).'/vendor/autoload.php'; -if (!array_key_exists('APP_ENV', $_SERVER)) { - $_SERVER['APP_ENV'] = $_ENV['APP_ENV'] ?? null; -} - -if ('prod' !== $_SERVER['APP_ENV']) { - if (!class_exists(Dotenv::class)) { - throw new RuntimeException('The "APP_ENV" environment variable is not set to "prod". Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.'); - } - +// Load cached env vars if the .env.local.php file exists +// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2) +if (is_array($env = @include dirname(__DIR__).'/.env.local.php')) { + $_SERVER += $env; + $_ENV += $env; +} elseif (!class_exists(Dotenv::class)) { + throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.'); +} else { + // load all the .env files (new Dotenv())->loadEnv(dirname(__DIR__).'/.env'); } diff --git a/symfony/framework-bundle/4.2/manifest.json b/symfony/framework-bundle/4.2/manifest.json index ad7fd41a9..ea46c0b02 100644 --- a/symfony/framework-bundle/4.2/manifest.json +++ b/symfony/framework-bundle/4.2/manifest.json @@ -19,6 +19,7 @@ }, "gitignore": [ "/.env.local", + "/.env.local.php", "/.env.*.local", "/%PUBLIC_DIR%/bundles/", "/%VAR_DIR%/",