- Created separate MoneyFlix project directory - Copied Node.js redirector from production server - Added CRM PHP code (Redirects module, Core classes, Config, Routes, Views) - Created comprehensive documentation (README_MONEYFLIX.md) - Added sync script to keep CRM code updated (sync-from-crm.sh) - Configured .gitignore for Node.js and PHP - Set up proper project structure for multi-client isolation This separates MoneyFlix from the main CRM to avoid confusion between different client systems and provides a dedicated environment for MoneyFlix-specific development and maintenance.
73 lines
2.2 KiB
PHP
73 lines
2.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Core;
|
|
|
|
/**
|
|
* Handles hostname-based branding configurations.
|
|
*/
|
|
class Branding
|
|
{
|
|
private static ?array $config = null;
|
|
private static ?array $currentBranding = null;
|
|
|
|
/**
|
|
* Loads the branding configuration file.
|
|
*/
|
|
private static function loadConfig(): void
|
|
{
|
|
if (self::$config === null) {
|
|
$configPath = __DIR__ . '/../Config/branding.php';
|
|
if (file_exists($configPath)) {
|
|
self::$config = require $configPath;
|
|
} else {
|
|
self::$config = [];
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the branding configuration for the current hostname.
|
|
*
|
|
* It first attempts an exact match on the hostname. If not found, it will
|
|
* iterate through configured hostnames to find a partial match (e.g., 'clienteA.com'
|
|
* will match a request from 'analytics.clienteA.com').
|
|
*
|
|
* @return array The configuration array for the matched host, or the default settings.
|
|
*/
|
|
public static function get(): array
|
|
{
|
|
if (self::$currentBranding !== null) {
|
|
return self::$currentBranding;
|
|
}
|
|
|
|
self::loadConfig();
|
|
|
|
$hostname = $_SERVER['HTTP_HOST'] ?? 'default';
|
|
$defaultConfig = self::$config['default'] ?? [];
|
|
|
|
// 1. Novo: Matching por string de hostnames separados por vírgula
|
|
foreach (self::$config as $configHost => $settings) {
|
|
if ($configHost === 'default') continue;
|
|
$patterns = explode(',', $configHost);
|
|
foreach ($patterns as $pattern) {
|
|
if (fnmatch(trim($pattern), $hostname)) {
|
|
self::$currentBranding = array_merge($defaultConfig, $settings);
|
|
return self::$currentBranding;
|
|
}
|
|
}
|
|
}
|
|
// 2. Fallback para default
|
|
self::$currentBranding = $defaultConfig;
|
|
return self::$currentBranding;
|
|
}
|
|
|
|
/**
|
|
* Get the current client ID based on hostname
|
|
*/
|
|
public static function getClientId(): string
|
|
{
|
|
$branding = self::get();
|
|
return $branding['client_id'] ?? 'default';
|
|
}
|
|
}
|