59 lines
2.0 KiB
PHP
59 lines
2.0 KiB
PHP
<?php
|
|
|
|
|
|
// env_loader.php
|
|
|
|
// 1. Leer el archivo .env respetando tu formato exacto
|
|
$env_path = __DIR__ . '/.env';
|
|
if (!file_exists($env_path)) {
|
|
die('Error: Archivo .env no encontrado');
|
|
}
|
|
|
|
$env_vars = [];
|
|
$lines = file($env_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
|
|
foreach ($lines as $line) {
|
|
$line = trim($line);
|
|
|
|
// Ignorar líneas vacías o comentarios completos
|
|
if (empty($line) || strpos($line, '#') === 0) {
|
|
continue;
|
|
}
|
|
|
|
// Separar nombre y valor (incluyendo comentarios después del valor)
|
|
list($name, $value) = array_pad(explode('=', $line, 2), 2, '');
|
|
|
|
// Limpiar el valor (eliminar comentarios y espacios)
|
|
$clean_value = trim(preg_replace('/\s*#.*$/', '', $value)); // Elimina comentarios después del valor
|
|
$env_vars[trim($name)] = $clean_value;
|
|
}
|
|
|
|
// 2. Obtener APP_MODE exactamente como está en tu .env (con espacios)
|
|
$app_mode = trim($env_vars['APP_MODE']); // Esto capturará " 0" o " 1" de tu formato actual
|
|
|
|
// 3. Convertir a booleano de manera segura
|
|
$is_production = ($app_mode === '1'); // Comparación estricta con '1'
|
|
|
|
// API
|
|
$api_url = $is_production ? $env_vars['API_URL'] : $env_vars['DEV_API_URL'];
|
|
$api_key_definition = $is_production ? $env_vars['API_KEY_DEFINITION'] : $env_vars['DEV_API_KEY_DEFINITION'];
|
|
$api_key = $is_production ? $env_vars['API_KEY'] : $env_vars['DEV_API_KEY'];
|
|
|
|
// Base de Datos
|
|
$db_host = $is_production ? $env_vars['DB_HOST'] : $env_vars['DEV_DB_HOST'];
|
|
$db_user = $is_production ? $env_vars['DB_USER'] : $env_vars['DEV_DB_USER'];
|
|
$db_pass = $is_production ? $env_vars['DB_PASS'] : $env_vars['DEV_DB_PASS'];
|
|
$db_name = $is_production ? $env_vars['DB_NAME'] : $env_vars['DEV_DB_NAME'];
|
|
|
|
// SAP
|
|
$sap_url = $is_production ? $env_vars['SAP_URL'] : $env_vars['DEV_SAP_URL'];
|
|
$sap_usr = $is_production ? $env_vars['SAP_USR'] : $env_vars['DEV_SAP_USR'];
|
|
$sap_pass = $is_production ? $env_vars['SAP_PASS'] : $env_vars['DEV_SAP_PASS'];
|
|
|
|
// Rutas
|
|
$cfdi_xml_path = $env_vars['CFDI_XML_FILE_URL'] ?? '';
|
|
|
|
$ruta = $api_url;
|
|
|
|
$loginUser = "$ruta/stripe/accessUser";
|