- 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.
156 lines
4.1 KiB
PHP
156 lines
4.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Core;
|
|
|
|
/**
|
|
* Sistema de Configuração Centralizada para Módulos
|
|
* Permite configuração isolada e hierárquica
|
|
*/
|
|
class ModuleConfig
|
|
{
|
|
private static ?ModuleConfig $instance = null;
|
|
private array $configs = [];
|
|
private array $moduleConfigs = [];
|
|
|
|
private function __construct() {}
|
|
|
|
public static function getInstance(): ModuleConfig
|
|
{
|
|
if (self::$instance === null) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Carregar configuração de um módulo
|
|
*/
|
|
public function loadModuleConfig(string $moduleName): void
|
|
{
|
|
$configPath = PathManager::getModulePath($moduleName) . "/config.php";
|
|
|
|
if (file_exists($configPath)) {
|
|
$this->moduleConfigs[$moduleName] = require $configPath;
|
|
} else {
|
|
$this->moduleConfigs[$moduleName] = [];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Obter configuração de um módulo
|
|
*/
|
|
public function getModuleConfig(string $moduleName, ?string $key = null, $default = null)
|
|
{
|
|
if (!isset($this->moduleConfigs[$moduleName])) {
|
|
$this->loadModuleConfig($moduleName);
|
|
}
|
|
|
|
if ($key === null) {
|
|
return $this->moduleConfigs[$moduleName];
|
|
}
|
|
|
|
return $this->moduleConfigs[$moduleName][$key] ?? $default;
|
|
}
|
|
|
|
/**
|
|
* Definir configuração de um módulo
|
|
*/
|
|
public function setModuleConfig(string $moduleName, string $key, $value): void
|
|
{
|
|
if (!isset($this->moduleConfigs[$moduleName])) {
|
|
$this->moduleConfigs[$moduleName] = [];
|
|
}
|
|
|
|
$this->moduleConfigs[$moduleName][$key] = $value;
|
|
}
|
|
|
|
/**
|
|
* Obter configuração global
|
|
*/
|
|
public function get(string $key, $default = null)
|
|
{
|
|
return $this->configs[$key] ?? $default;
|
|
}
|
|
|
|
/**
|
|
* Definir configuração global
|
|
*/
|
|
public function set(string $key, $value): void
|
|
{
|
|
$this->configs[$key] = $value;
|
|
}
|
|
|
|
/**
|
|
* Carregar configuração de cliente
|
|
*/
|
|
public function loadClientConfig(string $clientId): void
|
|
{
|
|
$configPath = PathManager::getModulesPath() . "/config.php";
|
|
|
|
if (file_exists($configPath)) {
|
|
$config = require $configPath;
|
|
$clientConfig = $config['clients'][$clientId] ?? [];
|
|
|
|
foreach ($clientConfig as $key => $value) {
|
|
$this->set($key, $value);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Verificar se um módulo está ativo para o cliente
|
|
*/
|
|
public function isModuleActive(string $moduleName, string $clientId): bool
|
|
{
|
|
$configPath = PathManager::getModulesPath() . "/config.php";
|
|
|
|
if (file_exists($configPath)) {
|
|
$config = require $configPath;
|
|
$clientConfig = $config['clients'][$clientId] ?? [];
|
|
|
|
if (isset($clientConfig['modules'])) {
|
|
foreach ($clientConfig['modules'] as $namespace => $modules) {
|
|
if (in_array($moduleName, $modules)) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Obter lista de módulos ativos para um cliente
|
|
*/
|
|
public function getActiveModules(string $clientId): array
|
|
{
|
|
$activeModules = [];
|
|
$configPath = PathManager::getModulesPath() . "/config.php";
|
|
|
|
if (file_exists($configPath)) {
|
|
$config = require $configPath;
|
|
$clientConfig = $config['clients'][$clientId] ?? [];
|
|
|
|
if (isset($clientConfig['modules'])) {
|
|
foreach ($clientConfig['modules'] as $namespace => $modules) {
|
|
foreach ($modules as $module) {
|
|
$activeModules[] = "$namespace:$module";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $activeModules;
|
|
}
|
|
|
|
/**
|
|
* Limpar todas as configurações
|
|
*/
|
|
public function clear(): void
|
|
{
|
|
$this->configs = [];
|
|
$this->moduleConfigs = [];
|
|
}
|
|
}
|