Make environment loading compatible with Plesk
This commit is contained in:
@@ -8,8 +8,12 @@ declare(strict_types=1);
|
||||
* env_vars.php file is loaded when present so existing installations keep
|
||||
* working during migration.
|
||||
*/
|
||||
$appFileEnvironment = [];
|
||||
|
||||
function app_load_env_file(string $filename): void
|
||||
{
|
||||
global $appFileEnvironment;
|
||||
|
||||
if (!is_file($filename)) {
|
||||
return;
|
||||
}
|
||||
@@ -57,8 +61,9 @@ function app_load_env_file(string $filename): void
|
||||
continue;
|
||||
}
|
||||
|
||||
// Real process variables and legacy configuration always take precedence.
|
||||
if (getenv($name) !== false) {
|
||||
// Non-empty process variables and legacy configuration take precedence.
|
||||
$processValue = getenv($name);
|
||||
if ($processValue !== false && trim((string)$processValue) !== '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -78,7 +83,7 @@ function app_load_env_file(string $filename): void
|
||||
continue;
|
||||
}
|
||||
|
||||
putenv($name . '=' . $value);
|
||||
$appFileEnvironment[$name] = $value;
|
||||
$_ENV[$name] = $value;
|
||||
}
|
||||
}
|
||||
@@ -92,8 +97,18 @@ app_load_env_file(dirname(__DIR__) . DIRECTORY_SEPARATOR . '.env');
|
||||
|
||||
function app_env(string $name, string $default = ''): string
|
||||
{
|
||||
global $appFileEnvironment;
|
||||
|
||||
$value = getenv($name);
|
||||
return $value === false ? $default : trim((string)$value);
|
||||
if ($value !== false && trim((string)$value) !== '') {
|
||||
return trim((string)$value);
|
||||
}
|
||||
|
||||
if (array_key_exists($name, $appFileEnvironment)) {
|
||||
return trim((string)$appFileEnvironment[$name]);
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
function app_env_int(string $name, int $default, int $min, int $max): int
|
||||
|
||||
Reference in New Issue
Block a user