3 * HTML2PDF Library - HTML2PDF Exception
5 * HTML => PDF convertor
6 * distributed under the LGPL License
9 * @author Laurent MINGUET <webmaster@html2pdf.fr>
10 * @copyright 2016 Laurent MINGUET
12 class HTML2PDF_exception
extends exception
14 protected $_tag = null;
15 protected $_html = null;
16 protected $_other = null;
17 protected $_image = null;
18 protected $_messageHtml = '';
21 * generate a HTML2PDF exception
23 * @param int $err error number
24 * @param mixed $other additionnal informations
25 * @param string $html additionnal informations
27 * @return HTML2PDF_exception
29 final public function __construct($err = 0, $other = null, $html = '')
34 case 1: // Unsupported tag
35 $msg = (HTML2PDF_locale
::get('err01'));
36 $msg = str_replace('[[OTHER]]', $other, $msg);
40 case 2: // too long sentence
41 $msg = (HTML2PDF_locale
::get('err02'));
42 $msg = str_replace('[[OTHER_0]]', $other[0], $msg);
43 $msg = str_replace('[[OTHER_1]]', $other[1], $msg);
44 $msg = str_replace('[[OTHER_2]]', $other[2], $msg);
47 case 3: // closing tag in excess
48 $msg = (HTML2PDF_locale
::get('err03'));
49 $msg = str_replace('[[OTHER]]', $other, $msg);
53 case 4: // tags closed in the wrong order
54 $msg = (HTML2PDF_locale
::get('err04'));
55 $msg = str_replace('[[OTHER]]', print_r($other, true), $msg);
58 case 5: // unclosed tag
59 $msg = (HTML2PDF_locale
::get('err05'));
60 $msg = str_replace('[[OTHER]]', print_r($other, true), $msg);
63 case 6: // image can not be loaded
64 $msg = (HTML2PDF_locale
::get('err06'));
65 $msg = str_replace('[[OTHER]]', $other, $msg);
66 $this->_image
= $other;
69 case 7: // too big TD content
70 $msg = (HTML2PDF_locale
::get('err07'));
73 case 8: // SVG tag not in DRAW tag
74 $msg = (HTML2PDF_locale
::get('err08'));
75 $msg = str_replace('[[OTHER]]', $other, $msg);
80 $msg = (HTML2PDF_locale
::get('err09'));
81 $msg = str_replace('[[OTHER_0]]', $other[0], $msg);
82 $msg = str_replace('[[OTHER_1]]', $other[1], $msg);
83 $this->_tag
= $other[0];
86 case 0: // specific error
92 // create the HTML message
93 $this->_messageHtml
= '<span style="color: #AA0000; font-weight: bold;">'."\n";
94 $this->_messageHtml
.= HTML2PDF_locale
::get('txt01', 'error: ').$err.'</span><br>'."\n";
95 $this->_messageHtml
.= HTML2PDF_locale
::get('txt02', 'file:').' '.$this->file
.'<br>'."\n";
96 $this->_messageHtml
.= HTML2PDF_locale
::get('txt03', 'line:').' '.$this->line
.'<br>'."\n";
97 $this->_messageHtml
.= '<br>'."\n";
98 $this->_messageHtml
.= $msg."\n";
100 // create the text message
101 $msg = HTML2PDF_locale
::get('txt01', 'error: ').$err.' : '.strip_tags($msg);
103 // add the optionnal html content
105 $this->_messageHtml
.= "<br><br>HTML : ...".trim(htmlentities($html)).'...';
106 $this->_html
= $html;
107 $msg.= ' HTML : ...'.trim($html).'...';
110 // save the other informations
111 $this->_other
= $other;
113 // construct the exception
114 parent
::__construct($msg, $err);
118 * get the message as string
121 * @return string $messageHtml
123 public function __toString()
125 return $this->_messageHtml
;
129 * get the html tag name
132 * @return string $tagName
134 public function getTAG()
140 * get the optional html code
143 * @return string $html
145 public function getHTML()
151 * get the optional other informations
154 * @return mixed $other
156 public function getOTHER()
158 return $this->_other
;
162 * get the image source
165 * @return string $imageSrc
167 public function getIMAGE()
169 return $this->_image
;