coreexception.class.inc.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 CoreException extends Exception
  25. {
  26. public function __construct($sIssue, $aContextData = null, $sImpact = '')
  27. {
  28. $this->m_sIssue = $sIssue;
  29. $this->m_sImpact = $sImpact;
  30. $this->m_aContextData = $aContextData ? $aContextData : array();
  31. $sMessage = $sIssue;
  32. if (!empty($sImpact)) $sMessage .= "($sImpact)";
  33. if (count($this->m_aContextData) > 0)
  34. {
  35. $sMessage .= ": ";
  36. $aContextItems = array();
  37. foreach($this->m_aContextData as $sKey => $value)
  38. {
  39. if (is_array($value))
  40. {
  41. $aPairs = array();
  42. foreach($value as $key => $val)
  43. {
  44. if (is_array($val))
  45. {
  46. $aPairs[] = $key.'=>('.implode(', ', $val).')';
  47. }
  48. else
  49. {
  50. $aPairs[] = $key.'=>'.$val;
  51. }
  52. }
  53. $sValue = '{'.implode('; ', $aPairs).'}';
  54. }
  55. else
  56. {
  57. $sValue = $value;
  58. }
  59. $aContextItems[] = "$sKey = $sValue";
  60. }
  61. $sMessage .= implode(', ', $aContextItems);
  62. }
  63. parent::__construct($sMessage, 0);
  64. }
  65. public function getHtmlDesc($sHighlightHtmlBegin = '<b>', $sHighlightHtmlEnd = '</b>')
  66. {
  67. return $this->getMessage();
  68. }
  69. public function getTraceAsHtml()
  70. {
  71. $aBackTrace = $this->getTrace();
  72. return MyHelpers::get_callstack_html(0, $this->getTrace());
  73. // return "<pre>\n".$this->getTraceAsString()."</pre>\n";
  74. }
  75. public function addInfo($sKey, $value)
  76. {
  77. $this->m_aContextData[$sKey] = $value;
  78. }
  79. public function getIssue()
  80. {
  81. return $this->m_sIssue;
  82. }
  83. public function getImpact()
  84. {
  85. return $this->m_sImpact;
  86. }
  87. public function getContextData()
  88. {
  89. return $this->m_aContextData;
  90. }
  91. }
  92. class CoreWarning extends CoreException
  93. {
  94. }
  95. class CoreUnexpectedValue extends CoreException
  96. {
  97. }
  98. class SecurityException extends CoreException
  99. {
  100. }
  101. ?>