Skip to content

Commit

Permalink
NEXT-16542 - Allow .env.local file loading
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Dec 16, 2021
1 parent 32b54ba commit 86bf952
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 61 deletions.
38 changes: 1 addition & 37 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,37 +1 @@
# This file is a "template" of which env vars need to be defined for your application
# Copy this file to .env file for development, create environment variables when deploying to production
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration

###> symfony/framework-bundle ###
APP_ENV=__APP_ENV__
APP_SECRET=8583a6ff63c5894a3195331701749943
APP_URL=__APP_URL__
#TRUSTED_PROXIES=127.0.0.1,127.0.0.2
#TRUSTED_HOSTS=localhost,example.com
###< symfony/framework-bundle ###

###> symfony/swiftmailer-bundle ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL=__APP_MAILER_URL__
###< symfony/swiftmailer-bundle ###

INSTANCE_ID=

DATABASE_URL=mysql://__DB_USER__:__DB_PASSWORD__@__DB_HOST__:__DB_PORT__/__DB_NAME__

COMPOSER_HOME=__COMPOSER_HOME__

BLUE_GREEN_DEPLOYMENT=1

SHOPWARE_ES_HOSTS=__SHOPWARE_ES_HOSTS__
SHOPWARE_ES_ENABLED=__SHOPWARE_ES_ENABLED__
SHOPWARE_ES_INDEXING_ENABLED=__SHOPWARE_ES_INDEXING_ENABLED__
SHOPWARE_ES_INDEX_PREFIX=__SHOPWARE_ES_INDEX_PREFIX__
SHOPWARE_HTTP_CACHE_ENABLED=__SHOPWARE_HTTP_CACHE_ENABLED__
SHOPWARE_HTTP_DEFAULT_TTL=__SHOPWARE_HTTP_DEFAULT_TTL__

STOREFRONT_PROXY_URL=__STOREFRONT_PROXY_URL__

__FEATURES__
# Use ./bin/console system:setup to generate a env file
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ variables:
# shopware 6
WEB_DOCUMENT_ROOT: '$CI_PROJECT_DIR/public'
MYSQL_ROOT_PASSWORD: root
DEFAULT_PLATFORM_BRANCH: master
DEFAULT_PLATFORM_BRANCH: trunk
LOG_STDOUT: $CI_PROJECT_DIR/stdout.log
CYPRESS_PERCY_USAGE: $CYPRESS_PERCY_USAGE
PERCY_BUILD_NAME: '000'
Expand Down
8 changes: 4 additions & 4 deletions bin/ci
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ use Symfony\Component\ErrorHandler\Debug;
set_time_limit(0);

$classLoader = require __DIR__ . '/../vendor/autoload.php';
$envFile = __DIR__ . '/../.env';

if (class_exists(Dotenv::class) && is_readable($envFile) && !is_dir($envFile)) {
(new Dotenv())->usePutenv()->load($envFile);
$projectRoot = dirname(__DIR__);
if (class_exists(Dotenv::class) && (file_exists($projectRoot . '/.env.local.php') || file_exists($projectRoot . '/.env') || file_exists($projectRoot . '/.env.dist'))) {
(new Dotenv())->usePutenv()->bootEnv(dirname(__DIR__) . '/.env');
}

if (!isset($_SERVER['PROJECT_ROOT'])) {
$_SERVER['PROJECT_ROOT'] = dirname(__DIR__);
$_SERVER['PROJECT_ROOT'] = $projectRoot;
}

$input = new ArgvInput();
Expand Down
9 changes: 4 additions & 5 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ if (!class_exists(Application::class)) {
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
}

$envFile = __DIR__ . '/../.env';

if (class_exists(Dotenv::class) && is_readable($envFile) && !is_dir($envFile)) {
(new Dotenv())->usePutenv()->load($envFile);
$projectRoot = dirname(__DIR__);
if (class_exists(Dotenv::class) && (file_exists($projectRoot . '/.env.local.php') || file_exists($projectRoot . '/.env') || file_exists($projectRoot . '/.env.dist'))) {
(new Dotenv())->usePutenv()->bootEnv(dirname(__DIR__) . '/.env');
}

if (!isset($_SERVER['PROJECT_ROOT'])) {
$_SERVER['PROJECT_ROOT'] = dirname(__DIR__);
$_SERVER['PROJECT_ROOT'] = $projectRoot;
}

$input = new ArgvInput();
Expand Down
20 changes: 6 additions & 14 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;

if (\PHP_VERSION_ID < 70400) {
if (\PHP_VERSION_ID < 70403) {
header('Content-type: text/html; charset=utf-8', true, 503);

echo '<h2>Error</h2>';
echo 'Your server is running PHP version ' . \PHP_VERSION . ' but Shopware 6 requires at least PHP 7.4.0';
echo 'Your server is running PHP version ' . \PHP_VERSION . ' but Shopware 6 requires at least PHP 7.4.3';
exit(1);
}

Expand Down Expand Up @@ -39,21 +39,13 @@
return;
}

// The check is to ensure we don't use .env if APP_ENV is defined
if (!isset($_SERVER['APP_ENV']) && !isset($_ENV['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.');
}
$envFile = __DIR__ . '/../.env';
if (file_exists($envFile)) {
(new Dotenv())
->usePutenv(true)
->load($envFile);
}
$projectRoot = dirname(__DIR__);
if (class_exists(Dotenv::class) && (file_exists($projectRoot . '/.env.local.php') || file_exists($projectRoot . '/.env') || file_exists($projectRoot . '/.env.dist'))) {
(new Dotenv())->usePutenv()->bootEnv(dirname(__DIR__) . '/.env');
}

$appEnv = $_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? 'dev';
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? ($appEnv !== 'prod'));
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? ($appEnv !== 'prod' && $appEnv !== 'e2e'));

if ($debug) {
umask(0000);
Expand Down

0 comments on commit 86bf952

Please sign in to comment.