mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-09 08:43:13 +08:00
Update to shlink-config 3.2.1, which fixes skipping config options with null value
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user