fix: Allow Docker Secrets to override empty environment variables
- Update get() method to treat empty strings as 'not set' for Docker Secrets resolution - Allows Docker Secrets (*_FILE pattern) to override empty values - Preserves original behavior: explicitly set empty strings are still returned - Fixes issue where RAPIDMAIL_USERNAME and RAPIDMAIL_PASSWORD appear empty even when Docker Secrets are available
This commit is contained in:
@@ -23,12 +23,19 @@ final readonly class Environment
|
||||
{
|
||||
$key = $this->keyToString($key);
|
||||
|
||||
// 1. Check if direct env var exists in internal array
|
||||
// 1. Check if direct env var exists in internal array and is not empty
|
||||
// Empty strings are treated as "not set" to allow Docker Secrets resolution
|
||||
if (isset($this->variables[$key])) {
|
||||
return $this->variables[$key];
|
||||
$value = $this->variables[$key];
|
||||
// If value is not empty, return it (non-empty values take precedence)
|
||||
if ($value !== '' && $value !== null) {
|
||||
return $value;
|
||||
}
|
||||
// If value is empty, continue to check Docker Secrets as fallback
|
||||
}
|
||||
|
||||
// 2. Docker Secrets support: Check for *_FILE pattern
|
||||
// This allows Docker Secrets to override empty values
|
||||
$secretValue = $this->secretsResolver->resolve($key, $this->variables);
|
||||
if ($secretValue !== null) {
|
||||
return $secretValue;
|
||||
@@ -38,11 +45,17 @@ final readonly class Environment
|
||||
// This handles cases where environment variables are set after Environment initialization
|
||||
// (common in PHP-FPM where vars may be set during request processing)
|
||||
$systemValue = $this->getFromSystemEnvironment($key);
|
||||
if ($systemValue !== null) {
|
||||
if ($systemValue !== null && $systemValue !== '') {
|
||||
return $systemValue;
|
||||
}
|
||||
|
||||
// 4. Return default
|
||||
// 4. If internal variable was set (even if empty), return it (to distinguish between "not set" and "empty")
|
||||
// This preserves the original behavior: if variable is explicitly set to empty string, return it
|
||||
if (isset($this->variables[$key])) {
|
||||
return $this->variables[$key];
|
||||
}
|
||||
|
||||
// 5. Return default
|
||||
return $default;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user