Files
emailtemplate.it/config/emailtemplate.conf.php
2026-02-09 01:38:39 +01:00

165 lines
6.2 KiB
PHP
Executable File

<?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')));
$host = '';
if (!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
$host = strtolower(trim(explode(',', (string)$_SERVER['HTTP_X_FORWARDED_HOST'])[0]));
} elseif (!empty($_SERVER['HTTP_HOST'])) {
$host = strtolower((string)$_SERVER['HTTP_HOST']);
}
if ($host !== '') {
$host = preg_replace('/:\\d+$/', '', $host);
if ($host === 'staging.emailtemplate.it') {
$env = 'staging';
} elseif (preg_match('/(^|\\.)emailtemplate\\.it$/', $host)) {
$env = 'prod';
}
}
$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',
'col_role' => 'role',
'customer_fk' => 'customer_id',
'customer_table'=> 'customers',
'customer_cols' => [
'name' => 'name',
'slug' => 'slug',
'status' => 'status',
'plan' => 'plan',
],
'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',
'content_items' => 'emailtemplate_content_items',
'content_sections' => 'emailtemplate_content_sections',
'content_versions' => 'emailtemplate_content_versions',
];
$tables = array_replace($tablesDefaults, $overrides['tables'] ?? []);
$placeholdersDefaults = [
'bridge' => [
'url' => getenv('EMAILTEMPLATE_PLACEHOLDER_URL') ?: '',
'token' => getenv('EMAILTEMPLATE_PLACEHOLDER_TOKEN') ?: '',
'cache_ttl' => (int)(getenv('EMAILTEMPLATE_PLACEHOLDER_CACHE') ?: 300),
],
];
$placeholders = array_replace_recursive($placeholdersDefaults, $overrides['placeholders'] ?? []);
$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'],
'content' => ['id'=>'id','name'=>'name','cat'=>'category','upd'=>'updated_at'],
'sections_config' => ['id'=>'id','name'=>'name','cat'=>null,'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,
'placeholders' => $placeholders,
];