coreexception.class.inc.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Exception management
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. class SecurityException extends CoreException
  25. {
  26. }
  27. class CoreException extends Exception
  28. {
  29. public function __construct($sIssue, $aContextData = null, $sImpact = '')
  30. {
  31. $this->m_sIssue = $sIssue;
  32. $this->m_sImpact = $sImpact;
  33. $this->m_aContextData = $aContextData ? $aContextData : array();
  34. $sMessage = $sIssue;
  35. if (!empty($sImpact)) $sMessage .= "($sImpact)";
  36. if (count($this->m_aContextData) > 0)
  37. {
  38. $sMessage .= ": ";
  39. $aContextItems = array();
  40. foreach($this->m_aContextData as $sKey => $value)
  41. {
  42. if (is_array($value))
  43. {
  44. $aPairs = array();
  45. foreach($value as $key => $val)
  46. {
  47. if (is_array($val))
  48. {
  49. $aPairs[] = $key.'=>('.implode(', ', $val).')';
  50. }
  51. else
  52. {
  53. $aPairs[] = $key.'=>'.$val;
  54. }
  55. }
  56. $sValue = '{'.implode('; ', $aPairs).'}';
  57. }
  58. else
  59. {
  60. $sValue = $value;
  61. }
  62. $aContextItems[] = "$sKey = $sValue";
  63. }
  64. $sMessage .= implode(', ', $aContextItems);
  65. }
  66. parent::__construct($sMessage, 0);
  67. }
  68. public function getHtmlDesc($sHighlightHtmlBegin = '<b>', $sHighlightHtmlEnd = '</b>')
  69. {
  70. return $this->getMessage();
  71. }
  72. public function getTraceAsHtml()
  73. {
  74. $aBackTrace = $this->getTrace();
  75. return MyHelpers::get_callstack_html(0, $this->getTrace());
  76. // return "<pre>\n".$this->getTraceAsString()."</pre>\n";
  77. }
  78. public function addInfo($sKey, $value)
  79. {
  80. $this->m_aContextData[$sKey] = $value;
  81. }
  82. public function getIssue()
  83. {
  84. return $this->m_sIssue;
  85. }
  86. public function getImpact()
  87. {
  88. return $this->m_sImpact;
  89. }
  90. public function getContextData()
  91. {
  92. return $this->m_aContextData;
  93. }
  94. }
  95. class CoreWarning extends CoreException
  96. {
  97. }
  98. ?>