coreexception.class.inc.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. // Copyright (C) 2010-2012 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Exception management
  20. *
  21. * @copyright Copyright (C) 2010-2012 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  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. /**
  102. * Throwned when querying on an object that exists in the database but is archived
  103. *
  104. * @see N.1108
  105. */
  106. class ArchivedObjectException extends CoreException
  107. {
  108. }
  109. ?>