Пример #1
0
 /**
  * Prints a debug backtrace
  *
  * @access public
  * @static
  */
 public static function backtrace($max = 15, $capture = false)
 {
     // disabled ?
     if (!self::_debug()) {
         return false;
     }
     $dump = array();
     $filenames = array();
     foreach (debug_backtrace() as $line) {
         // Keep the 'max' in check..
         if ($max-- < 1) {
             break;
         }
         // Get a descriptive 'name' for the function..
         $name = sprintf("%s(%s)", Dumper::trimString($line['function'], 40), !empty($line['args']) ? count($line['args']) : "");
         if (!empty($line['type'])) {
             $name = sprintf("%s&nbsp;%s&nbsp;%s", Dumper::trimString($line['class'], 40), $line['type'], $name);
         }
         $thisdump = array();
         $thisdump['file'] = $line['file'];
         if (!empty($line['file'])) {
             $filenames[] = $line['file'];
         }
         if (!empty($line['line'])) {
             $thisdump['line'] = $line['line'];
         }
         if (!empty($line['args'])) {
             $thisdump['args'] = $line['args'];
         }
         $dump[$name] = $thisdump;
     }
     // get the common prefix for all the used filenames..
     $commonprefix = Dumper::commonPrefix($filenames);
     // iterate over the results, cleaning up the filenames..
     foreach ($dump as $key => $line) {
         $dump[$key]['file'] = str_replace($commonprefix, "…" . DIRECTORY_SEPARATOR, $dump[$key]['file']);
     }
     // render it
     if (!$capture) {
         Dumper::dump($dump);
     } else {
         return Dumper::dump($dump, DUMPER_CAPTURE);
     }
 }