Skip to content

Commit

Permalink
allow setting datadir with env var
Browse files Browse the repository at this point in the history
The environment variable loader converts the variable names to lowercase,
which prevents the DATADIR from being settable through this mechanism.

This patch stops lowercasing selected variables to allow changing them.
  • Loading branch information
jtojnar committed Jun 18, 2018
1 parent 5e935cd commit 4432ac0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions common.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,18 @@

// overwrite config with ENV variables
$env_prefix = $f3->get('env_prefix');
foreach ($f3->get('ENV') as $key => $value) {
if (strncasecmp($key, $env_prefix, strlen($env_prefix)) == 0) {
$f3->set(strtolower(substr($key, strlen($env_prefix))), $value);
foreach ($f3->get('ENV') as $envKey => $value) {
// if variable name starts with $env_prefix
if (strncasecmp($envKey, $env_prefix, strlen($env_prefix)) == 0) {
$key = substr($envKey, strlen($env_prefix)); // remove the prefix

// most keys are lowercase but there are some exceptions and
// we still want to be able to set them using environment variable
if (!in_array($key, ['BASEDIR', 'DATADIR'])) {
$key = strtolower($key);
}

$f3->set($key, $value);
}
}

Expand Down

0 comments on commit 4432ac0

Please sign in to comment.