Skip to content
Snippets Groups Projects
Commit b31ae325 authored by jurgenhaas's avatar jurgenhaas
Browse files

Give value in .env higher priority than OS env variable

parent 8a9d7acd
No related branches found
No related tags found
No related merge requests found
......@@ -117,8 +117,7 @@ final class Dotenv {
* @param bool $overwrite
*/
public function put($key, $value, $overwrite = FALSE) {
$envContent = file_exists('.env') ? file_get_contents('.env') : '';
$data = $this->dotenv->parse($envContent);
$data = $this->parse();
$key = strtoupper($key);
if (!$overwrite && isset($data[$key])) {
return;
......@@ -187,11 +186,24 @@ final class Dotenv {
return $item;
}
/**
* Parse the local .env file and return the content as an array.
*
* @return array
*/
private function parse() {
$envContent = file_exists('.env') ? file_get_contents('.env') : '';
return $this->dotenv->parse($envContent);
}
/**
* Load the local .env file.
*/
private function load() {
try {
foreach ($this->parse() as $key => $value) {
unset($_SERVER[$key]);
}
$this->dotenv->load('.env');
}
catch (\Exception $ex) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment