6 declare(strict_types = 1);
22 private $envFile =
'';
29 private $envExampleFile =
'';
52 $this->envFile = $envFile;
53 $this->envExists = file_exists($envFile);
54 $this->envExampleFile = realpath(FW_BP .
"/etc/config/.env.example");
62 private function parseEnvFile(): array
64 $envExampleFile = file(
65 $this->envExampleFile,
66 FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES
70 if ($this->envExists) {
73 FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES
76 $envContents = $this->parseEnvFileLines($envFile);
79 return array_merge($this->parseEnvFileLines($envExampleFile), $envContents);
87 private function parseEnvFileLines(array $file): array
90 foreach ($file as $line) {
92 if (strpos($line,
'#') !== 0) {
93 list($key,
$value) = explode(
'=', $line);
110 $envData .= $key .
'=' .
$value . PHP_EOL;
123 if (empty($this->env)) {
124 $this->env = $this->parseEnvFile();
__construct(string $envFile='')
putEnvFile(array $config=[])