Skip to content

Commit

Permalink
Add support for .env files
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewbaggett committed Jun 10, 2024
1 parent f08ff23 commit 7a3b093
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Services/EnvironmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,21 @@ class EnvironmentService
public function __construct()
{
$this->environmentVariables = array_merge($_SERVER, $_ENV);
if(file_exists(APP_ROOT . '/.env')){
$env = file_get_contents(APP_ROOT . '/.env');
$lines = explode("\n", $env);
foreach($lines as $line){
$line = trim($line);
if($line == ''){
continue;
}
$parts = explode('=', $line);
$this->environmentVariables[$parts[0]] = $parts[1];
}
}

ksort($this->environmentVariables);

}

public function has(string $key): bool
Expand Down

0 comments on commit 7a3b093

Please sign in to comment.