exception.class.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * HTML2PDF Librairy - HTML2PDF Exception
  4. *
  5. * HTML => PDF convertor
  6. * distributed under the LGPL License
  7. *
  8. * @author Laurent MINGUET <webmaster@html2pdf.fr>
  9. * @version 4.03
  10. */
  11. class HTML2PDF_exception extends exception
  12. {
  13. protected $_tag = null;
  14. protected $_html = null;
  15. protected $_other = null;
  16. protected $_image = null;
  17. protected $_messageHtml = '';
  18. /**
  19. * generate a HTML2PDF exception
  20. *
  21. * @param int $err error number
  22. * @param mixed $other additionnal informations
  23. * @return string $html optionnal code HTML associated to the error
  24. */
  25. final public function __construct($err = 0, $other = null, $html = '')
  26. {
  27. // read the error
  28. switch($err)
  29. {
  30. case 1: // Unsupported tag
  31. $msg = (HTML2PDF_locale::get('err01'));
  32. $msg = str_replace('[[OTHER]]', $other, $msg);
  33. $this->_tag = $other;
  34. break;
  35. case 2: // too long sentence
  36. $msg = (HTML2PDF_locale::get('err02'));
  37. $msg = str_replace('[[OTHER_0]]', $other[0], $msg);
  38. $msg = str_replace('[[OTHER_1]]', $other[1], $msg);
  39. $msg = str_replace('[[OTHER_2]]', $other[2], $msg);
  40. break;
  41. case 3: // closing tag in excess
  42. $msg = (HTML2PDF_locale::get('err03'));
  43. $msg = str_replace('[[OTHER]]', $other, $msg);
  44. $this->_tag = $other;
  45. break;
  46. case 4: // tags closed in the wrong order
  47. $msg = (HTML2PDF_locale::get('err04'));
  48. $msg = str_replace('[[OTHER]]', print_r($other, true), $msg);
  49. break;
  50. case 5: // unclosed tag
  51. $msg = (HTML2PDF_locale::get('err05'));
  52. $msg = str_replace('[[OTHER]]', print_r($other, true), $msg);
  53. break;
  54. case 6: // image can not be loaded
  55. $msg = (HTML2PDF_locale::get('err06'));
  56. $msg = str_replace('[[OTHER]]', $other, $msg);
  57. $this->_image = $other;
  58. break;
  59. case 7: // too big TD content
  60. $msg = (HTML2PDF_locale::get('err07'));
  61. break;
  62. case 8: // SVG tag not in DRAW tag
  63. $msg = (HTML2PDF_locale::get('err08'));
  64. $msg = str_replace('[[OTHER]]', $other, $msg);
  65. $this->_tag = $other;
  66. break;
  67. case 9: // deprecated
  68. $msg = (HTML2PDF_locale::get('err09'));
  69. $msg = str_replace('[[OTHER_0]]', $other[0], $msg);
  70. $msg = str_replace('[[OTHER_1]]', $other[1], $msg);
  71. $this->_tag = $other[0];
  72. break;
  73. case 0: // specific error
  74. default:
  75. $msg = $other;
  76. break;
  77. }
  78. // create the HTML message
  79. $this->_messageHtml = '<span style="color: #AA0000; font-weight: bold;">'.HTML2PDF_locale::get('txt01', 'error: ').$err.'</span><br>';
  80. $this->_messageHtml.= HTML2PDF_locale::get('txt02', 'file:').' '.$this->file.'<br>';
  81. $this->_messageHtml.= HTML2PDF_locale::get('txt03', 'line:').' '.$this->line.'<br>';
  82. $this->_messageHtml.= '<br>';
  83. $this->_messageHtml.= $msg;
  84. // create the text message
  85. $msg = HTML2PDF_locale::get('txt01', 'error: ').$err.' : '.strip_tags($msg);
  86. // add the optionnal html content
  87. if ($html) {
  88. $this->_messageHtml.= "<br><br>HTML : ...".trim(htmlentities($html)).'...';
  89. $this->_html = $html;
  90. $msg.= ' HTML : ...'.trim($html).'...';
  91. }
  92. // save the other informations
  93. $this->_other = $other;
  94. // construct the exception
  95. parent::__construct($msg, $err);
  96. }
  97. /**
  98. * get the message as string
  99. *
  100. * @access public
  101. * @return string $messageHtml
  102. */
  103. public function __toString()
  104. {
  105. return $this->_messageHtml;
  106. }
  107. /**
  108. * get the html tag name
  109. *
  110. * @access public
  111. * @return string $tagName
  112. */
  113. public function getTAG()
  114. {
  115. return $this->_tag;
  116. }
  117. /**
  118. * get the optional html code
  119. *
  120. * @access public
  121. * @return string $html
  122. */
  123. public function getHTML()
  124. {
  125. return $this->_html;
  126. }
  127. /**
  128. * get the optional other informations
  129. *
  130. * @access public
  131. * @return mixed $other
  132. */
  133. public function getOTHER()
  134. {
  135. return $this->_other;
  136. }
  137. /**
  138. * get the image source
  139. *
  140. * @access public
  141. * @return string $imageSrc
  142. */
  143. public function getIMAGE()
  144. {
  145. return $this->_image;
  146. }
  147. }