Skip to content

Commit

Permalink
Fix configuration loading according to doc page #105
Browse files Browse the repository at this point in the history
  • Loading branch information
odan committed Nov 8, 2022
1 parent 9f900a5 commit 42fb077
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions config/settings.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

// Load .env file if located in the project root directory
// Load .env file if located above the project root directory
// (\Dotenv\Dotenv::createImmutable(__DIR__ . '/../../'))->safeLoad();

// Define environment
Expand All @@ -10,10 +10,18 @@
$settings = require __DIR__ . '/defaults.php';

// Overwrite default settings with environment specific local settings
$configFiles = sprintf('%s/{local.%s,env,../../env}.php', __DIR__, $_ENV['APP_ENV']);
$configFiles = [
__DIR__ . sprintf('/local.%s.php', $_ENV['APP_ENV']),
__DIR__ . '/env.php',
__DIR__ . '/../../env.php',
];

foreach (glob($configFiles, GLOB_BRACE) as $file) {
$local = require $file;
foreach ($configFiles as $configFile) {
if (!file_exists($configFile)) {
continue;
}

$local = require $configFile;
if (is_callable($local)) {
$settings = $local($settings);
}
Expand Down

0 comments on commit 42fb077

Please sign in to comment.