This commit is contained in:
Flatlogic Bot 2026-03-25 16:40:11 +00:00
parent fe7ebfad4d
commit cdb6be6798
3 changed files with 6585 additions and 22 deletions

View File

@ -90,6 +90,11 @@ class MailService
} }
private static function loadConfig(): array private static function loadConfig(): array
{ {
static $cachedConfig = null;
if (is_array($cachedConfig)) {
return $cachedConfig;
}
$configPath = __DIR__ . '/config.php'; $configPath = __DIR__ . '/config.php';
if (!file_exists($configPath)) { if (!file_exists($configPath)) {
throw new \RuntimeException('Mail config not found. Copy mail/config.sample.php to mail/config.php and fill in credentials.'); throw new \RuntimeException('Mail config not found. Copy mail/config.sample.php to mail/config.php and fill in credentials.');
@ -98,7 +103,9 @@ class MailService
if (!is_array($cfg)) { if (!is_array($cfg)) {
throw new \RuntimeException('Invalid mail config format: expected array'); throw new \RuntimeException('Invalid mail config format: expected array');
} }
return $cfg;
$cachedConfig = $cfg;
return $cachedConfig;
} }
// Send a contact message // Send a contact message

View File

@ -2,15 +2,18 @@
// Mail configuration sourced from environment variables. // Mail configuration sourced from environment variables.
// No secrets are stored here; the file just maps env -> config array for MailService. // No secrets are stored here; the file just maps env -> config array for MailService.
function env_val(string $key, $default = null) { if (!function_exists('env_val')) {
function env_val(string $key, $default = null) {
$v = getenv($key); $v = getenv($key);
return ($v === false || $v === null || $v === '') ? $default : $v; return ($v === false || $v === null || $v === '') ? $default : $v;
}
} }
// Fallback: if critical vars are missing from process env, try to parse executor/.env // Fallback: if critical vars are missing from process env, try to parse executor/.env
// This helps in web/Apache contexts where .env is not exported. // This helps in web/Apache contexts where .env is not exported.
// Supports simple KEY=VALUE lines; ignores quotes and comments. // Supports simple KEY=VALUE lines; ignores quotes and comments.
function load_dotenv_if_needed(array $keys): void { if (!function_exists('load_dotenv_if_needed')) {
function load_dotenv_if_needed(array $keys): void {
$missing = array_filter($keys, fn($k) => getenv($k) === false || getenv($k) === ''); $missing = array_filter($keys, fn($k) => getenv($k) === false || getenv($k) === '');
if (empty($missing)) return; if (empty($missing)) return;
static $loaded = false; static $loaded = false;
@ -23,7 +26,7 @@ function load_dotenv_if_needed(array $keys): void {
if (!str_contains($line, '=')) continue; if (!str_contains($line, '=')) continue;
[$k, $v] = array_map('trim', explode('=', $line, 2)); [$k, $v] = array_map('trim', explode('=', $line, 2));
// Strip potential surrounding quotes // Strip potential surrounding quotes
$v = trim($v, "\"' "); $v = trim($v, "\"' " );
// Do not override existing env // Do not override existing env
if ($k !== '' && (getenv($k) === false || getenv($k) === '')) { if ($k !== '' && (getenv($k) === false || getenv($k) === '')) {
putenv("{$k}={$v}"); putenv("{$k}={$v}");
@ -31,6 +34,7 @@ function load_dotenv_if_needed(array $keys): void {
} }
$loaded = true; $loaded = true;
} }
}
} }
load_dotenv_if_needed([ load_dotenv_if_needed([

File diff suppressed because it is too large Load Diff