0
0
Fork 0
mirror of https://github.com/nextcloud/docker.git synced 2025-06-16 00:04:48 +02:00

feat: make database configuration environment variables independent

Add utility function for environment variable / from file support.

Signed-off-by: Anderson Entwistle <46688047+aentwist@users.noreply.github.com>
This commit is contained in:
Anderson Entwistle 2023-03-15 00:56:49 -04:00
parent 8df9b2617e
commit 8b81e556e4
4 changed files with 41 additions and 32 deletions

27
.config/util.php Normal file
View file

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* Gets the value of an environment variable or the contents of the file
* at the path specified by its value if it exists with a suffix of "_FILE"
*/
function getFileEnv(string $envVarName, ?string $defaultValue): ?string {
$FILE_ENV_VAR_SUFFIX = "_FILE";
$fileEnvVarName = "$envVarName$FILE_ENV_VAR_SUFFIX";
$filename = getenv($fileEnvVarName);
$envVarValue = getenv($envVarName);
$configValue = null;
if ($filename && file_exists($filename)) {
$configValue = trim(file_get_contents($filename));
} else if ($envVarValue) {
$configValue = $envVarValue;
} else if ($defaultValue) {
$configValue = $defaultValue;
}
return $configValue;
}
?>