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:
parent
8df9b2617e
commit
8b81e556e4
4 changed files with 41 additions and 32 deletions
27
.config/util.php
Normal file
27
.config/util.php
Normal 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;
|
||||
}
|
||||
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue