Update to shlink-config 3.2.1, which fixes skipping config options with null value

This commit is contained in:
Alejandro Celaya
2024-10-17 09:33:53 +02:00
parent aef04af4f0
commit 4b7b530f49
3 changed files with 35 additions and 18 deletions

View File

@@ -97,6 +97,23 @@ enum EnvVars: string
return env($this->value) ?? $this->loadFromFileEnv() ?? $this->defaultValue();
}
/**
* Checks if an equivalent environment variable exists with the `_FILE` suffix. If so, it loads its value as a file,
* reads it, and returns its contents.
* This is useful when loading Shlink with docker compose and using secrets.
* See https://docs.docker.com/compose/use-secrets/
*/
private function loadFromFileEnv(): string|int|bool|null
{
$file = env(sprintf('%s_FILE', $this->value));
if ($file === null || ! is_file($file)) {
return null;
}
$content = file_get_contents($file);
return $content ? parseEnvVar($content) : null;
}
private function defaultValue(): string|int|bool|null
{
return match ($this) {
@@ -153,23 +170,6 @@ enum EnvVars: string
};
}
/**
* Checks if an equivalent environment variable exists with the `_FILE` suffix. If so, it loads its value as a file,
* reads it, and returns its contents.
* This is useful when loading Shlink with docker compose and using secrets.
* See https://docs.docker.com/compose/use-secrets/
*/
private function loadFromFileEnv(): string|int|bool|null
{
$file = env(sprintf('%s_FILE', $this->value));
if ($file === null || ! is_file($file)) {
return null;
}
$content = file_get_contents($file);
return $content ? parseEnvVar($content) : null;
}
public function existsInEnv(): bool
{
return $this->loadFromEnv() !== null;