coreexception.class.inc.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. class SecurityException extends CoreException
  3. {
  4. }
  5. class CoreException extends Exception
  6. {
  7. public function __construct($sIssue, $aContextData = null, $sImpact = '')
  8. {
  9. $this->m_sIssue = $sIssue;
  10. $this->m_sImpact = $sImpact;
  11. $this->m_aContextData = $aContextData ? $aContextData : array();
  12. $sMessage = $sIssue;
  13. if (!empty($sImpact)) $sMessage .= "($sImpact)";
  14. if (count($this->m_aContextData) > 0)
  15. {
  16. $sMessage .= ": ";
  17. $aContextItems = array();
  18. foreach($this->m_aContextData as $sKey => $value)
  19. {
  20. if (is_array($value))
  21. {
  22. $aPairs = array();
  23. foreach($value as $key => $val)
  24. {
  25. if (is_array($val))
  26. {
  27. $aPairs[] = $key.'=>('.implode(', ', $val).')';
  28. }
  29. else
  30. {
  31. $aPairs[] = $key.'=>'.$val;
  32. }
  33. }
  34. $sValue = '{'.implode('; ', $aPairs).'}';
  35. }
  36. else
  37. {
  38. $sValue = $value;
  39. }
  40. $aContextItems[] = "$sKey = $sValue";
  41. }
  42. $sMessage .= implode(', ', $aContextItems);
  43. }
  44. parent::__construct($sMessage, 0);
  45. }
  46. public function getHtmlDesc($sHighlightHtmlBegin = '<b>', $sHighlightHtmlEnd = '</b>')
  47. {
  48. return $this->getMessage();
  49. }
  50. public function getTraceAsHtml()
  51. {
  52. $aBackTrace = $this->getTrace();
  53. return MyHelpers::get_callstack_html(0, $this->getTrace());
  54. // return "<pre>\n".$this->getTraceAsString()."</pre>\n";
  55. }
  56. public function addInfo($sKey, $value)
  57. {
  58. $this->m_aContextData[$sKey] = $value;
  59. }
  60. }
  61. class CoreWarning extends CoreException
  62. {
  63. }
  64. ?>