Skip to content

Commit ec7146b

Browse files
authored
Merge pull request #155 from joomlatools/feature/154-env
Parse environment variables in the config.yaml file
2 parents f567f31 + fc8ccb0 commit ec7146b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/Joomlatools/Console/Command/Configurable.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,22 @@ protected function _getConfigOverride($name)
4242
{
4343
$file = sprintf('%s/.joomlatools/console/config.yaml', trim(`echo ~`));
4444

45-
if (file_exists($file)) {
46-
$this->_config = Yaml::parseFile($file);
45+
if (file_exists($file))
46+
{
47+
$file_contents = \file_get_contents($file);
48+
$env = $_ENV;
49+
50+
// Replace longest keys first
51+
uksort($env, function($a, $b){
52+
return strlen($b) - strlen($a);
53+
});
54+
55+
// Replace environment variables in the file
56+
foreach ($env as $key => $value) {
57+
$file_contents = \str_replace('$'.$key, $value, $file_contents);
58+
}
59+
60+
$this->_config = Yaml::parse($file_contents);
4761
} else {
4862
$this->_config = false;
4963
}

0 commit comments

Comments
 (0)