source: trunk/client/inc/hpdf403/_class/exception.class.php@ 418

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