Primer subida completa
This commit is contained in:
35
config/config.php
Executable file
35
config/config.php
Executable file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/error_logging.php';
|
||||
|
||||
$envFile = dirname(__DIR__) . '/.env';
|
||||
if (file_exists($envFile)) {
|
||||
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
foreach ($lines as $line) {
|
||||
if (strpos(trim($line), '#') === 0) continue;
|
||||
if (strpos($line, '=') !== false) {
|
||||
list($key, $value) = explode('=', $line, 2);
|
||||
$key = trim($key);
|
||||
$value = trim($value);
|
||||
$_ENV[$key] = $value;
|
||||
putenv("$key=$value");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!defined('BASE_PATH')) {
|
||||
define('BASE_PATH', dirname(__DIR__));
|
||||
}
|
||||
|
||||
return [
|
||||
'db' => [
|
||||
'host' => getenv('DB_HOST') ?: 'localhost',
|
||||
'port' => getenv('DB_PORT') ?: '3306',
|
||||
'database' => getenv('DB_NAME') ?: 'contenedor_ibiza',
|
||||
'username' => getenv('DB_USER') ?: 'root',
|
||||
'password' => getenv('DB_PASS') ?: '',
|
||||
],
|
||||
'site_url' => getenv('SITE_URL') ?: 'http://localhost:8080',
|
||||
'telegram_bot_token' => getenv('TELEGRAM_BOT_TOKEN') ?: '',
|
||||
'session_name' => getenv('SESSION_NAME') ?: 'contenedor_session',
|
||||
];
|
||||
58
config/error_logging.php
Executable file
58
config/error_logging.php
Executable file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 0);
|
||||
ini_set('log_errors', 1);
|
||||
|
||||
$logFile = __DIR__ . '/../logs/error.log';
|
||||
|
||||
if (!file_exists(dirname($logFile))) {
|
||||
mkdir(dirname($logFile), 0755, true);
|
||||
}
|
||||
|
||||
ini_set('error_log', $logFile);
|
||||
|
||||
set_error_handler(function($errno, $errstr, $errfile, $errline) use ($logFile) {
|
||||
$timestamp = date('Y-m-d H:i:s');
|
||||
$errorType = match($errno) {
|
||||
E_ERROR => 'ERROR',
|
||||
E_WARNING => 'WARNING',
|
||||
E_PARSE => 'PARSE',
|
||||
E_NOTICE => 'NOTICE',
|
||||
E_CORE_ERROR => 'CORE_ERROR',
|
||||
E_CORE_WARNING => 'CORE_WARNING',
|
||||
E_COMPILE_ERROR => 'COMPILE_ERROR',
|
||||
E_COMPILE_WARNING => 'COMPILE_WARNING',
|
||||
E_USER_ERROR => 'USER_ERROR',
|
||||
E_USER_WARNING => 'USER_WARNING',
|
||||
E_USER_NOTICE => 'USER_NOTICE',
|
||||
E_STRICT => 'STRICT',
|
||||
E_RECOVERABLE_ERROR => 'RECOVERABLE_ERROR',
|
||||
E_DEPRECATED => 'DEPRECATED',
|
||||
E_USER_DEPRECATED => 'USER_DEPRECATED',
|
||||
default => 'UNKNOWN'
|
||||
};
|
||||
|
||||
$message = "[$timestamp] PHP $errorType: $errstr in $errfile on line $errline";
|
||||
error_log($message . PHP_EOL, 3, $logFile);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
set_exception_handler(function($exception) use ($logFile) {
|
||||
$timestamp = date('Y-m-d H:i:s');
|
||||
$message = "[$timestamp] UNCAUGHT EXCEPTION: " . get_class($exception) . ": " .
|
||||
$exception->getMessage() . " in " . $exception->getFile() .
|
||||
" on line " . $exception->getLine() . "\n" . $exception->getTraceAsString();
|
||||
error_log($message . PHP_EOL, 3, $logFile);
|
||||
});
|
||||
|
||||
register_shutdown_function(function() use ($logFile) {
|
||||
$error = error_get_last();
|
||||
if ($error && in_array($error['type'], [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR])) {
|
||||
$timestamp = date('Y-m-d H:i:s');
|
||||
$message = "[$timestamp] FATAL: " . $error['message'] . " in " .
|
||||
$error['file'] . " on line " . $error['line'];
|
||||
error_log($message . PHP_EOL, 3, $logFile);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user