Skip to content

Commit

Permalink
fix: fix dotenv loader to work without request matcher and to support…
Browse files Browse the repository at this point in the history
… grouping
  • Loading branch information
fago authored Apr 16, 2024
1 parent b8c06b9 commit 2dbfe11
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions dotenv/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ public static function prepareAppEnvironment() {
if (file_exists(__DIR__ . '/sites/all.env')) {
$vars .= file_get_contents(__DIR__ . '/sites/all.env') . "\n";
}
// Support dots in the environment name and load files by prefix.
// This allows grouping environments by host having shared settings.
if (strpos($phapp_env, '.') !== FALSE) {
$parts = explode('.', $phapp_env, 2);
if (file_exists(__DIR__ . '/sites/all.env-' . $parts[0] . '.env')) {
$vars .= file_get_contents(__DIR__ . '/sites/all.env-' . $parts[0] . '.env') . "\n";
}
}
// Support per-environment all.env files.
if (file_exists(__DIR__ . '/sites/all.env-' . $phapp_env . '.env')) {
$vars .= file_get_contents(__DIR__ . '/sites/all.env-' . $phapp_env . '.env') . "\n";
Expand Down Expand Up @@ -209,7 +217,6 @@ public static function getSiteVariables($site = NULL, $site_variant = '') {
$dotenv->populate($dotenv->parse(PhappEnvironmentLoader::prepareDeterminedEnvironment()), TRUE);

// Match the request and prepare site-specific dotenv vars.
$site = drunomics\MultisiteRequestMatcher\RequestMatcher::getInstance()
->match();
$site = PhappEnvironmentLoader::determineActiveSite();
$dotenv->populate($dotenv->parse(PhappEnvironmentLoader::prepareAppEnvironment()), TRUE);
}

0 comments on commit 2dbfe11

Please sign in to comment.