56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
<?php
|
||
|
||
if (! function_exists('settings')) {
|
||
function settings(string $key, $default = null) {
|
||
return app(\App\Support\SettingsRepository::class)->get($key, $default);
|
||
}
|
||
}
|
||
|
||
if (!function_exists('domain_host')) {
|
||
function domain_host(string $sub = null): string
|
||
{
|
||
$base = env('BASE_DOMAIN', 'example.com');
|
||
return $sub ? "{$sub}.{$base}" : $base;
|
||
}
|
||
}
|
||
|
||
if (!function_exists('ui_host')) {
|
||
function ui_host(): string
|
||
{
|
||
return domain_host(env('UI_SUB', 'ui'));
|
||
}
|
||
}
|
||
|
||
if (!function_exists('webmail_host')) {
|
||
function webmail_host(): string
|
||
{
|
||
return domain_host(env('WEBMAIL_SUB', 'webmail'));
|
||
}
|
||
}
|
||
|
||
if (!function_exists('mta_host')) {
|
||
function mta_host(?int $domainId = null): string
|
||
{
|
||
// 1️⃣ Vorrang: Datenbankwert (z. B. aus der domains-Tabelle)
|
||
if ($domainId) {
|
||
try {
|
||
$domain = \App\Models\Domain::find($domainId);
|
||
if ($domain && !empty($domain->mta_host)) {
|
||
return $domain->mta_host;
|
||
}
|
||
} catch (\Throwable $e) {
|
||
// DB evtl. noch nicht migriert — fallback auf env
|
||
}
|
||
}
|
||
|
||
// 2️⃣ ENV-Variante (z. B. MTA_SUB=mail01)
|
||
$sub = env('MTA_SUB');
|
||
if ($sub) {
|
||
return domain_host($sub);
|
||
}
|
||
|
||
// 3️⃣ Notfall: statischer Fallback
|
||
return domain_host('mx');
|
||
}
|
||
}
|