Files
emailtemplate.it/config/emailtemplate.conf.php
2025-12-05 01:20:55 +01:00

127 lines
4.7 KiB
PHP

<?php
declare(strict_types=1);
$bootstrapTried = false;
$bootstrapLoaded = false;
$bootstrapCandidates = [__DIR__ . '/config.php'];
$envHint = getenv('APP_ENV') ?: (getenv('APP_ENV_FILE') ?: null);
if ($envHint) {
$bootstrapCandidates[] = __DIR__ . '/' . $envHint . '/config.php';
}
$bootstrapCandidates[] = __DIR__ . '/staging/config.php';
$bootstrapCandidates[] = __DIR__ . '/prod/config.php';
foreach ($bootstrapCandidates as $bootstrapConfig) {
if ($bootstrapConfig && is_file($bootstrapConfig)) {
$bootstrapTried = true;
require_once $bootstrapConfig;
$bootstrapLoaded = true;
break;
}
}
if (!$bootstrapLoaded) {
throw new RuntimeException('No environment config found in config/ or its subdirectories.');
}
$overrides = $GLOBALS['EMAILTEMPLATE_OVERRIDES'] ?? [];
$env = (string)($overrides['env'] ?? (defined('APP_ENV') ? APP_ENV : (getenv('APP_ENV') ?: 'local')));
$baseUrl = (string)($overrides['base_url'] ?? (defined('APP_URL_PRIMARY') ? APP_URL_PRIMARY : (getenv('APP_BASE_URL') ?: '')));
$cookieDomainDefault = (string)($overrides['cookie_domain'] ?? ($overrides['auth']['cookie_domain'] ?? (defined('APP_COOKIE_DOMAIN') ? APP_COOKIE_DOMAIN : (defined('APP_DOMAIN_PRIMARY') ? '.' . APP_DOMAIN_PRIMARY : ''))));
$sessionNameDefault = (string)($overrides['session_name'] ?? ($overrides['auth']['session_name'] ?? (defined('APP_COOKIE_PREFIX') ? APP_COOKIE_PREFIX . 'session' : 'et_session')));
$projectDbDefaults = [
'db_host' => getenv('DB_HOST') ?: getenv('DB_TPL_HOST') ?: 'localhost',
'db_name' => getenv('DB_NAME') ?: getenv('DB_TPL_NAME') ?: 'd044ae9e',
'db_user' => getenv('DB_USER') ?: getenv('DB_TPL_USER') ?: 'd044ae9e',
'db_pass' => getenv('DB_PASS') ?: getenv('DB_TPL_PASS') ?: '9BVUn)Töcü@ÖVÜfgO8!J',
'db_charset' => getenv('DB_CHARSET') ?: 'utf8mb4',
'db_port' => (int)(getenv('DB_PORT') ?: 3306),
'prefix' => defined('APP_PREFIX') ? APP_PREFIX . '_' : 'emailtemplate_',
];
$legacyOverrides = [];
if (isset($overrides['project'])) {
$legacyOverrides = $overrides['project'];
} elseif (isset($overrides['templates'])) {
$legacyOverrides = $overrides['templates'];
}
$projectDb = array_replace($projectDbDefaults, $legacyOverrides, $overrides['projectdb'] ?? $overrides['dbsettings'] ?? []);
$cors = $overrides['cors'] ?? (getenv('CORS_ORIGIN') ?: '*');
$authDefaults = [
'session_name' => $sessionNameDefault,
'cookie_domain' => $cookieDomainDefault,
'cookie_secure' => $env === 'prod',
'cookie_httponly' => true,
'cookie_samesite' => 'Lax',
'cookie' => [
'domain' => $cookieDomainDefault,
'secure' => $env === 'prod',
'httponly' => true,
'samesite' => 'Lax',
],
'db' => [
'table' => 'customer_users',
'col_user' => 'email',
'col_pass' => 'password_hash',
'col_name' => 'name',
'col_id' => 'id',
'col_status' => 'is_active',
'active_values' => ['active','1',1],
'legacy' => 'md5',
],
];
$auth = array_replace_recursive($authDefaults, $overrides['auth'] ?? []);
$smtpDefaults = [
'host' => 'smtp.example.com',
'port' => 587,
'user' => 'smtp-user',
'pass' => 'smtp-pass',
'secure' => 'tls',
'from_email' => 'no-reply@example.com',
'from_name' => 'EmailTemplate',
];
$smtp = array_replace($smtpDefaults, $overrides['smtp'] ?? []);
$exportDefaults = [
'api_keys' => ['dev-key-123', 'noch-ein-key'],
];
$export = array_replace_recursive($exportDefaults, $overrides['export'] ?? []);
$multiDefaults = [
'tenant_col' => 'customer_id',
'map_session_to'=> 'id',
];
$multi = array_replace($multiDefaults, $overrides['multi'] ?? []);
$tablesDefaults = [
'templates' => 'emailtemplate_templates',
'sections' => 'emailtemplate_sections',
'blocks' => 'emailtemplate_blocks',
'snippets' => 'emailtemplate_snippets',
];
$tables = array_replace($tablesDefaults, $overrides['tables'] ?? []);
$columnsDefaults = [
'templates' => ['id'=>'id','name'=>'name','desc'=>null,'cat'=>null,'upd'=>'updated_at'],
'sections' => ['id'=>'id','name'=>'name','cat'=>null,'upd'=>'updated_at'],
'blocks' => ['id'=>'id','name'=>'name','cat'=>'category','upd'=>'updated_at'],
'snippets' => ['id'=>'id','name'=>'name','cat'=>'category','upd'=>'updated_at'],
];
$columns = array_replace_recursive($columnsDefaults, $overrides['columns'] ?? []);
return [
'projectdb' => $projectDb,
'cors' => $cors,
'env' => $env,
'base_url' => $baseUrl,
'auth' => $auth,
'smtp' => $smtp,
'export' => $export,
'multi' => $multi,
'tables' => $tables,
'columns' => $columns,
];