/** * ฟังก์ชั่นจัดการ error ของ database * * @param string $sql * @param string $message */ protected function logError($sql, $message) { $trace = debug_backtrace(); $trace = next($trace); // บันทึก error Logger::create()->error($sql . ' : <em>' . $message . '</em> in <b>' . $trace['file'] . '</b> on line <b>' . $trace['line'] . '</b>'); }
case E_RECOVERABLE_ERROR: $type = 'Recoverable error'; break; default: $type = 'PHP Error'; } \Kotchasan\Log\Logger::create()->error('<br>' . $type . ' : <em>' . $errstr . '</em> in <b>' . $errfile . '</b> on line <b>' . $errline . '</b>'); }); set_exception_handler(function ($e) { $tract = $e->getTrace(); if (empty($tract)) { $tract = array('file' => $e->getFile(), 'line' => $e->getLine()); } else { $tract = next($tract); } \Kotchasan\Log\Logger::create()->error('<br>Exception : <em>' . $e->getMessage() . '</em> in <b>' . $tract['file'] . '</b> on line <b>' . $tract['line'] . '</b>'); }); } /** * ตรวจสอบและคืนค่าชื่อไฟล์รวมพาธของคลาส * * @param string $className * @return string|null คืนค่าไฟล์รวมพาธของคลาส ถ้าไม่พบคืนค่า null */ function getClassPath($className) { $className = str_replace('\\', '/', $className); if (preg_match('/^Kotchasan\\/([a-zA-Z]+)Interface$/', $className, $match)) { if (is_file(VENDOR_DIR . 'Interfaces/' . $match[1] . 'Interface.php')) { return VENDOR_DIR . 'Interfaces/' . $match[1] . 'Interface.php'; }
/** * ฟังก์ชั่นบันทึกการ query sql * * @param string $type * @param string $sql * @param array $values (options) */ protected function log($type, $sql, $values = array()) { if (DB_LOG == true) { $datas = array('<b>' . $type . ' :</b> ' . Text::replace($sql, $values)); foreach (debug_backtrace() as $a => $item) { if (isset($item['file']) && isset($item['line'])) { if ($item['function'] == 'all' || $item['function'] == 'first' || $item['function'] == 'count' || $item['function'] == 'save' || $item['function'] == 'find' || $item['function'] == 'execute') { $datas[] = '<br>[' . $a . '] <b>' . $item['function'] . '</b> in <b>' . $item['file'] . '</b> line <b>' . $item['line'] . '</b>'; break; } } } // บันทึก log Logger::create()->info(implode('', $datas)); } }