Esempio n. 1
0
File: log.php Progetto: Borvik/Munla
 /**
  * Triggers an error
  * 
  * Serializes data to be passed to the error handler, such as message, file and line number.
  * That data is then submitted to trigger_error - and the serialized message must be under 1024 bytes.
  * Long messages/file names could cause problems - though situations like that are not common.
  * 
  * @param int $level The designated error type for this error (use E_USER family of constants).
  * @param string $message The error message for this error (limited to 1024 bytes)
  * 
  * @return void
  */
 protected static function trigger_error($level, $message)
 {
     if (!config::DEBUG_MODE && in_array($level, array(E_USER_WARNING, E_USER_NOTICE))) {
         return;
     }
     if (!is_string($message)) {
         ob_start();
         var_dump($message);
         $message = ob_get_contents();
         ob_end_clean();
     }
     $caller = null;
     $nonLog = null;
     $nonMunla = null;
     $stack = debug_backtrace();
     next($stack);
     list($k, $v) = each($stack);
     do {
         if (!isset($v['file'])) {
             continue;
         }
         if (!isset($caller)) {
             $caller = $v;
         }
         if (!isset($nonLog) && $v['file'] != __FILE__ && (!array_key_exists('class', $v) || $v['class'] != 'log') && !in_array($v['function'], array('error', 'warning', 'notice', 'debug'))) {
             $nonLog = $v;
         }
         if (!isset($nonMunla) && strtolower(substr($v['file'], 0, strlen(MUNLA_CORE_DIR))) != MUNLA_CORE_DIR) {
             $nonMunla = $v;
             break;
         }
     } while (list($k, $v) = each($stack));
     $caller = get::notnull($nonMunla, $nonLog, $caller);
     //get::notnull($nonMunla, $nonLog, $caller);
     if (!isset($caller) && count($stack) > 0) {
         $caller = count($stack) > 1 ? $stack[1] : $stack[0];
     } elseif (!isset($caller)) {
         $caller = array('file' => __FILE__, 'line' => __LINE__);
     }
     //$errorMessage = serialize(array('message' => $message, 'file' => $caller['file'], 'line' => $caller['line']));
     //trigger_error($errorMessage, $level);
     self::error_handler($level, $message, $caller['file'], $caller['line'], true);
 }