diff --git a/src/Framework/Config/Environment.php b/src/Framework/Config/Environment.php index 884e933f..48c4c1fe 100644 --- a/src/Framework/Config/Environment.php +++ b/src/Framework/Config/Environment.php @@ -177,7 +177,14 @@ final readonly class Environment // Resolve Docker Secrets for variables that are empty or not set // This ensures that variables like DB_PASSWORD are resolved from their *_FILE counterparts $resolved = []; + + // First pass: Process existing variables foreach ($all as $key => $value) { + // Skip *_FILE variables (we'll resolve them below) + if (str_ends_with($key, '_FILE')) { + continue; + } + // If variable is empty or not set, check for Docker Secret if (empty($value) || $value === '' || $value === null) { $secretValue = $this->secretsResolver->resolve($key, $all); @@ -186,9 +193,29 @@ final readonly class Environment continue; } } - // Include non-empty values and *_FILE variables + // Include non-empty values $resolved[$key] = $value; } + + // Second pass: Check for *_FILE variables that don't have corresponding resolved values + // This handles cases where a *_FILE exists but the variable itself is not in the array + foreach ($all as $key => $value) { + if (str_ends_with($key, '_FILE')) { + // Extract the base key name (e.g., APP_KEY from APP_KEY_FILE) + $baseKey = substr($key, 0, -5); // Remove '_FILE' suffix + + // If base key is not set or empty, try to resolve it + if (!isset($resolved[$baseKey]) || empty($resolved[$baseKey])) { + $secretValue = $this->secretsResolver->resolve($baseKey, $all); + if ($secretValue !== null) { + $resolved[$baseKey] = $secretValue; + } + } + + // Always include *_FILE variables in output + $resolved[$key] = $value; + } + } if ($sorted) { ksort($resolved); @@ -243,7 +270,7 @@ final readonly class Environment } /** - * Factory method für .env file loading + * Factory method f?r .env file loading */ public static function fromFile(FilePath|string $envPath): self { @@ -263,7 +290,7 @@ final readonly class Environment } /** - * Für Tests + * F?r Tests */ public function withVariable(string $key, mixed $value): self {