Skip to content

Commit

Permalink
Allowed to push env vars into config arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
hiqsol committed Oct 24, 2019
1 parent d238de7 commit 7fa31d1
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/configs/Params.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,28 @@ protected function pushEnvVars($vars): array
{
$env = $this->builder->getConfig('dotenv')->getValues();
if (!empty($vars)) {
foreach (array_keys($vars) as $key) {
$envKey = strtoupper(strtr($key, '.', '_'));
if (isset($env[$envKey])) {
$vars[$key] = $env[$envKey];
foreach ($vars as $key => &$value) {
if (is_array($value)) {
foreach (array_keys($value) as $subkey) {
$envKey = $this->getEnvKey($key . '_' . $subkey);
if (isset($env[$envKey])) {
$value[$subkey] = $env[$envKey];
}
}
} else {
$envKey = $this->getEnvKey($key);
if (isset($env[$envKey])) {
$vars[$key] = $env[$envKey];
}
}
}
}

return $vars;
}

private function getEnvKey(string $key): string
{
return strtoupper(strtr($key, '.', '_'));
}
}

0 comments on commit 7fa31d1

Please sign in to comment.