diff --git a/src/Framework/Config/Environment.php b/src/Framework/Config/Environment.php index 8bd8acce..fa3f8584 100644 --- a/src/Framework/Config/Environment.php +++ b/src/Framework/Config/Environment.php @@ -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; }