From 9531fdbd35bc8526c497202e4effaac6f75c610c Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Thu, 25 Jun 2026 01:14:13 +0200 Subject: [PATCH] yxsad --- src/App/ConfigLoader.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/App/ConfigLoader.php b/src/App/ConfigLoader.php index 77bb992b..cb117a3a 100644 --- a/src/App/ConfigLoader.php +++ b/src/App/ConfigLoader.php @@ -14,7 +14,7 @@ final class ConfigLoader $basePath = $projectRoot . '/config/' . $name . '.php'; $config = is_file($basePath) ? require $basePath : []; - $appEnv = getenv('APP_ENV') ?: 'local'; + $appEnv = self::detectEnvironment(); $envPath = $projectRoot . '/config/' . $appEnv . '/' . $name . '.php'; if (!is_file($envPath)) { @@ -45,4 +45,27 @@ final class ConfigLoader return $base; } + + private static function detectEnvironment(): string + { + $appEnv = trim((string) getenv('APP_ENV')); + if ($appEnv !== '') { + return $appEnv; + } + + $host = strtolower(trim((string) ($_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? ''))); + if ($host === '') { + return 'local'; + } + + if (str_contains($host, 'staging.')) { + return 'staging'; + } + + if (str_contains($host, 'desktop.kusche.berlin')) { + return 'prod'; + } + + return 'local'; + } }