You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.2 KiB

  1. <?php
  2. /**
  3. * Обработчик эксепшенов
  4. *
  5. * @copyright
  6. * @link
  7. * @package Majestic
  8. * @subpackage Core
  9. * @since
  10. * @version SVN: $Id$
  11. * @filesource $URL$
  12. */
  13. class MJException extends Exception
  14. {
  15. private $line_range = 6;
  16. public function terminate()
  17. {
  18. if (!DEBUG_ENABLE) {
  19. throw new StaticPageException(500);
  20. }
  21. $return = "<b>MJ Error:</b> ";
  22. $return .= str_replace("\n", "<br/>\n", $this->getMessage())."<br>\n";
  23. $trace = $this->getTrace();
  24. $file = reset($trace);
  25. //смещение в трейсе, указаное при вызове эксепшена (2й параметр). Нужно для более инофрмативного вывода
  26. if ($shift = abs($this->getCode())) {
  27. while($shift--) {
  28. $file = next($trace);
  29. }
  30. }
  31. if ($fp = fopen($file['file'], 'r')) {
  32. $error_line = $file['line'];
  33. $start = $error_line - $this->line_range;
  34. $end = $error_line + $this->line_range;
  35. $i = 1;
  36. $return .= "<pre style=\"background-color:#e4e4e4\">";
  37. while ($line = fgets($fp, 4096) and $i<=$end) {
  38. $line = htmlspecialchars($line);
  39. if ($i >= $start && $i <= $end) {
  40. if ($i == $error_line) $return .= '<div style="background-color:#cccccc">'.$i.' '.$line.'</div>';
  41. else $return .= $i.' '.$line;
  42. }
  43. $i++;
  44. }
  45. $return .= "</pre>";
  46. fclose($fp);
  47. }
  48. $return .= '<table border="1" cellpadding="2" cellspacing="0"> <caption><b>Backtrace</b></caption>';
  49. $return .= "\n<tr><td><b>".$this->getFile().'</b></td><td><b>'.$this->getLine().'</b></td></tr>';
  50. foreach($trace as $row) {
  51. if (isset($row['file'])) { //throwing exception from __call method will not return file and line
  52. $return .= "\n<tr".($file['file'] == $row['file'] ? ' style="background-color:#ffcccc"': '')."><td>".$row['file'].'</td><td>'.$row['line'].'</td></tr>';
  53. }
  54. }
  55. return $return . '</table>';
  56. }
  57. }
  58. ?>