Skip to content

Always load vars defined in .env files, providing .env.local.php for prod #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Jan 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions symfony/console/3.3/bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
17 changes: 13 additions & 4 deletions symfony/flex/1.0/.env
Original file line number Diff line number Diff line change
@@ -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
18 changes: 9 additions & 9 deletions symfony/framework-bundle/3.3/config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions symfony/framework-bundle/3.3/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"gitignore": [
"/.env.local",
"/.env.local.php",
"/.env.*.local",
"/%PUBLIC_DIR%/bundles/",
"/%VAR_DIR%/",
Expand Down
18 changes: 9 additions & 9 deletions symfony/framework-bundle/4.2/config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
1 change: 1 addition & 0 deletions symfony/framework-bundle/4.2/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"gitignore": [
"/.env.local",
"/.env.local.php",
"/.env.*.local",
"/%PUBLIC_DIR%/bundles/",
"/%VAR_DIR%/",
Expand Down