This commit is contained in:
Lizandro Guarnizo
2026-06-09 16:44:39 -05:00
parent 4e6913c41e
commit ab8b5ae620
9 changed files with 1590 additions and 323 deletions
+27 -28
View File
@@ -5,6 +5,32 @@
* Fecha: 4 de enero de 2026 - Sistema de autenticación unificado
*/
// ── Cargar .env ANTES de definir cualquier constante ──────────────────────────
// Si no se hace aquí, getenv() devuelve vacío y los define() usan el fallback
// 'mysql' (nombre del contenedor Docker) en lugar de la IP real de la BD.
if (!function_exists('loadEnvFile')) {
function loadEnvFile($path) {
if (!file_exists($path)) {
return false;
}
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos($line, '#') === 0 || strpos($line, '=') === false) {
continue;
}
[$name, $value] = explode('=', $line, 2);
$name = trim($name);
$value = trim($value, " \t\n\r\0\x0B\"'");
if (!array_key_exists($name, $_ENV)) {
$_ENV[$name] = $value;
putenv("$name=$value");
}
}
return true;
}
}
loadEnvFile(__DIR__ . '/../.env');
// Configuración de la base de datos - 100% desde variables de entorno (o .env)
define('DB_HOST', getenv('DB_HOST') ?: 'mysql');
define('DB_PORT', getenv('DB_PORT') ?: '3306');
@@ -46,34 +72,7 @@ define('SYSTEM_MODULES', [
'resultados' => 'Resultados',
]);
// Función para cargar archivo .env
if (!function_exists('loadEnvFile')) {
function loadEnvFile($path) {
if (!file_exists($path)) {
return false;
}
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos($line, '#') === 0 || strpos($line, '=') === false) {
continue;
}
[$name, $value] = explode('=', $line, 2);
$name = trim($name);
$value = trim($value, " \t\n\r\0\x0B\"'");
if (!array_key_exists($name, $_ENV)) {
$_ENV[$name] = $value;
putenv("$name=$value");
}
}
return true;
}
}
// Cargar .env si existe
loadEnvFile(__DIR__ . '/../.env');
// loadEnvFile ya fue definida y ejecutada al inicio del archivo.
// Cargar autoloader de Composer si existe (solo una vez)
$composerAutoload = __DIR__ . '/../vendor/autoload.php';