Skip to content

Commit 5727045

Browse files
committed
update env loading as text
1 parent b7f3532 commit 5727045

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/Ubiquity/config/Configuration.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,17 @@ public static function getTheoreticalLoadedConfigFiles($appEnv):array{
9494
}
9595

9696
public static function loadConfigWithoutEval(string $filename='config'): array{
97-
$origContent=\file_get_contents(\ROOT."config/$filename.php");
98-
$result=\preg_replace('/getenv\(\'(.*?)\'\)/','"getenv(\'$1\')"',$origContent);
99-
$result=\preg_replace('/getenv\(\"(.*?)\"\)/',"'getenv(\"\$1\")'",$result);
100-
$tmpFilename=\ROOT.'cache/config/tmp.cache.php';
101-
if(\file_put_contents($tmpFilename,$result)) {
102-
return include $tmpFilename;
97+
if(file_exists(\ROOT."config/$filename.php")) {
98+
$origContent = \file_get_contents(\ROOT . "config/$filename.php");
99+
$result = \preg_replace('/getenv\(\'(.*?)\'\)/', '"getenv(\'$1\')"', $origContent);
100+
$result = \preg_replace('/getenv\(\"(.*?)\"\)/', "'getenv(\"\$1\")'", $result);
101+
$tmpFilename = \ROOT . 'cache/config/tmp.cache.php';
102+
if (\file_put_contents($tmpFilename, $result)) {
103+
return include $tmpFilename;
104+
}
105+
return self::loadMainConfig();
103106
}
104-
return self::loadMainConfig();
107+
return [];
105108
}
106109

107110
public static function saveConfig(array $contentArray,string $configFilename='config') {

src/Ubiquity/config/EnvFile.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,13 @@ public static function load(?string $path=null, string $filename='.env'): array
9191
}
9292
return [];
9393
}
94+
95+
public static function loadContent(?string $path=null, string $filename='.env'): string {
96+
$path??=self::$ENV_ROOT;
97+
if(\file_exists($path.$filename)) {
98+
return \file_get_contents($path.$filename);
99+
}
100+
return '';
101+
}
94102

95103
}

0 commit comments

Comments
 (0)