SenException.class.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. // +--------------------------------------------------------------------------
  3. // | Senthot [ DEVELOPED BY ME ]
  4. // +--------------------------------------------------------------------------
  5. // | Copyright (c) 2005-2013 http://www.senthot.com All rights reserved.
  6. // | License ( http://www.apache.org/licenses/LICENSE-2.0 )
  7. // | Author: ms134n ( [email protected] )
  8. // +--------------------------------------------------------------------------
  9. /**
  10. * Senthot system exception base class
  11. * @category Sen
  12. * @package Sen
  13. * @subpackage Core
  14. * @author ms134n <[email protected]>
  15. */
  16. class SenException extends Exception {
  17. /**
  18. * Exception Types
  19. * @var string
  20. * @access private
  21. */
  22. private $type;
  23. // The existence of extra debugging information
  24. private $extra;
  25. /**
  26. * Architecture function
  27. * @access public
  28. * @param string $message Exception information
  29. */
  30. public function __construct($message,$code=0,$extra=false) {
  31. parent::__construct($message,$code);
  32. $this->type = get_class($this);
  33. $this->extra = $extra;
  34. }
  35. /**
  36. * Abnormal output All classes have passed __toString exception handling method output error
  37. * Each exception are written to the system log
  38. * This method can be overridden by child classes
  39. * @access public
  40. * @return array
  41. */
  42. public function __toString() {
  43. $trace = $this->getTrace();
  44. if($this->extra)
  45. // By throw_exception thrown to remove excess debug information
  46. array_shift($trace);
  47. $this->class = isset($trace[0]['class'])?$trace[0]['class']:'';
  48. $this->function = isset($trace[0]['function'])?$trace[0]['function']:'';
  49. $this->file = $trace[0]['file'];
  50. $this->line = $trace[0]['line'];
  51. $file = file($this->file);
  52. $traceInfo = '';
  53. $time = date('y-m-d H:i:m');
  54. foreach($trace as $t) {
  55. $traceInfo .= '['.$time.'] '.$t['file'].' ('.$t['line'].') ';
  56. $traceInfo .= $t['class'].$t['type'].$t['function'].'(';
  57. $traceInfo .= implode(', ', $t['args']);
  58. $traceInfo .=")\n";
  59. }
  60. $error['message'] = $this->message;
  61. $error['type'] = $this->type;
  62. $error['detail'] = L('_MODULE_').'['.MODULE_NAME.'] '.L('_ACTION_').'['.ACTION_NAME.']'."\n";
  63. $error['detail'] .= ($this->line-2).': '.$file[$this->line-3];
  64. $error['detail'] .= ($this->line-1).': '.$file[$this->line-2];
  65. $error['detail'] .= '<font color="#FF6600" >'.($this->line).': <strong>'.$file[$this->line-1].'</strong></font>';
  66. $error['detail'] .= ($this->line+1).': '.$file[$this->line];
  67. $error['detail'] .= ($this->line+2).': '.$file[$this->line+1];
  68. $error['class'] = $this->class;
  69. $error['function'] = $this->function;
  70. $error['file'] = $this->file;
  71. $error['line'] = $this->line;
  72. $error['trace'] = $traceInfo;
  73. // Record Exception Journal
  74. if(C('LOG_EXCEPTION_RECORD')) {
  75. Log::Write('('.$this->type.') '.$this->message);
  76. }
  77. return $error ;
  78. }
  79. }