PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.5
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.5
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / Libraries / Pear / Error.php

Error.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.0.5, at back/Libraries/Pear/Error.php

302 lines 7.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Libraries\Pear;
4
5 /**
6 * Standard PEAR error class for PHP 4
7 *
8 * This class is supserseded by {@link PEAR_Exception} in PHP 5
9 *
10 * @category pear
11 * @package PEAR
12 * @author Stig Bakken <[email protected]>
13 * @author Tomas V.V. Cox <[email protected]>
14 * @author Gregory Beaver <[email protected]>
15 * @copyright 1997-2006 The PHP Group
16 * @license http://opensource.org/licenses/bsd-license.php New BSD License
17 * @version Release: 1.10.16
18 * @link http://pear.php.net/manual/en/core.pear.pear-error.php
19 * @see Pear::raiseError(), Pear::throwError()
20 * @since Class available since PHP 4.0.2
21 */
22 class Error
23 {
24 var $error_message_prefix = '';
25 var $mode = PEAR_ERROR_RETURN;
26 var $level = E_USER_NOTICE;
27 var $code = -1;
28 var $message = '';
29 var $userinfo = '';
30 var $backtrace = null;
31 var $callback = null;
32
33 /**
34 * Error constructor
35 *
36 * @param string $message message
37 *
38 * @param int $code (optional) error code
39 *
40 * @param int $mode (optional) error mode, one of: PEAR_ERROR_RETURN,
41 * PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER,
42 * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION
43 *
44 * @param mixed $options (optional) error level, _OR_ in the case of
45 * PEAR_ERROR_CALLBACK, the callback function or object/method
46 * tuple.
47 *
48 * @param string $userinfo (optional) additional user/debug info
49 *
50 * @access public
51 *
52 */
53 function __construct(
54 $message = 'unknown error',
55 $code = null,
56 $mode = null,
57 $options = null,
58 $userinfo = null
59 ) {
60 if ($mode === null) {
61 $mode = PEAR_ERROR_RETURN;
62 }
63 $this->message = $message;
64 $this->code = $code;
65 $this->mode = $mode;
66 $this->userinfo = $userinfo;
67
68 $skiptrace = Pear::getStaticProperty('AcyMailing\Libraries\Pear\Error', 'skiptrace');
69
70 if (!$skiptrace) {
71 $this->backtrace = debug_backtrace();
72 if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) {
73 unset($this->backtrace[0]['object']);
74 }
75 }
76
77 if ($mode & PEAR_ERROR_CALLBACK) {
78 $this->level = E_USER_NOTICE;
79 $this->callback = $options;
80 } else {
81 if ($options === null) {
82 $options = E_USER_NOTICE;
83 }
84
85 $this->level = $options;
86 $this->callback = null;
87 }
88
89 if ($this->mode & PEAR_ERROR_PRINT) {
90 if (is_null($options) || is_int($options)) {
91 $format = "%s";
92 } else {
93 $format = $options;
94 }
95
96 printf($format, $this->getMessage());
97 }
98
99 if ($this->mode & PEAR_ERROR_TRIGGER) {
100 trigger_error($this->getMessage(), $this->level);
101 }
102
103 if ($this->mode & PEAR_ERROR_DIE) {
104 $msg = $this->getMessage();
105 if (is_null($options) || is_int($options)) {
106 $format = "%s";
107 if (substr($msg, -1) != "\n") {
108 $msg .= "\n";
109 }
110 } else {
111 $format = $options;
112 }
113 printf($format, $msg);
114 exit($code);
115 }
116
117 if ($this->mode & PEAR_ERROR_CALLBACK && is_callable($this->callback)) {
118 call_user_func($this->callback, $this);
119 }
120
121 if ($this->mode & PEAR_ERROR_EXCEPTION) {
122 trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
123 throw new \Exception($this->message, $this->code);
124 }
125 }
126
127 /**
128 * Get the error mode from an error object.
129 *
130 * @return int error mode
131 * @access public
132 */
133 function getMode()
134 {
135 return $this->mode;
136 }
137
138 /**
139 * Get the callback function/method from an error object.
140 *
141 * @return mixed callback function or object/method array
142 * @access public
143 */
144 function getCallback()
145 {
146 return $this->callback;
147 }
148
149 /**
150 * Get the error message from an error object.
151 *
152 * @return string full error message
153 * @access public
154 */
155 function getMessage()
156 {
157 return ($this->error_message_prefix.$this->message);
158 }
159
160 /**
161 * Get error code from an error object
162 *
163 * @return int error code
164 * @access public
165 */
166 function getCode()
167 {
168 return $this->code;
169 }
170
171 /**
172 * Get the name of this error/exception.
173 *
174 * @return string error/exception name (type)
175 * @access public
176 */
177 function getType()
178 {
179 return get_class($this);
180 }
181
182 /**
183 * Get additional user-supplied information.
184 *
185 * @return string user-supplied information
186 * @access public
187 */
188 function getUserInfo()
189 {
190 return $this->userinfo;
191 }
192
193 /**
194 * Get additional debug information supplied by the application.
195 *
196 * @return string debug information
197 * @access public
198 */
199 function getDebugInfo()
200 {
201 return $this->getUserInfo();
202 }
203
204 /**
205 * Get the call backtrace from where the error was generated.
206 * Supported with PHP 4.3.0 or newer.
207 *
208 * @param int $frame (optional) what frame to fetch
209 *
210 * @return array Backtrace, or NULL if not available.
211 * @access public
212 */
213 function getBacktrace($frame = null)
214 {
215 if (defined('PEAR_IGNORE_BACKTRACE')) {
216 return null;
217 }
218 if ($frame === null) {
219 return $this->backtrace;
220 }
221
222 return $this->backtrace[$frame];
223 }
224
225 function addUserInfo($info)
226 {
227 if (empty($this->userinfo)) {
228 $this->userinfo = $info;
229 } else {
230 $this->userinfo .= " ** $info";
231 }
232 }
233
234 function __toString()
235 {
236 return $this->getMessage();
237 }
238
239 /**
240 * Make a string representation of this object.
241 *
242 * @return string a string with an object summary
243 * @access public
244 */
245 function toString()
246 {
247 $modes = [];
248 $levels = [
249 E_USER_NOTICE => 'notice',
250 E_USER_WARNING => 'warning',
251 E_USER_ERROR => 'error',
252 ];
253 if ($this->mode & PEAR_ERROR_CALLBACK) {
254 if (is_array($this->callback)) {
255 $callback = (is_object($this->callback[0])
256 ?
257 strtolower(get_class($this->callback[0]))
258 :
259 $this->callback[0]).'::'.
260 $this->callback[1];
261 } else {
262 $callback = $this->callback;
263 }
264
265 return sprintf(
266 '[%s: message="%s" code=%d mode=callback '.
267 'callback=%s prefix="%s" info="%s"]',
268 strtolower(get_class($this)),
269 $this->message,
270 $this->code,
271 $callback,
272 $this->error_message_prefix,
273 $this->userinfo
274 );
275 }
276 if ($this->mode & PEAR_ERROR_PRINT) {
277 $modes[] = 'print';
278 }
279 if ($this->mode & PEAR_ERROR_TRIGGER) {
280 $modes[] = 'trigger';
281 }
282 if ($this->mode & PEAR_ERROR_DIE) {
283 $modes[] = 'die';
284 }
285 if ($this->mode & PEAR_ERROR_RETURN) {
286 $modes[] = 'return';
287 }
288
289 return sprintf(
290 '[%s: message="%s" code=%d mode=%s level=%s '.
291 'prefix="%s" info="%s"]',
292 strtolower(get_class($this)),
293 $this->message,
294 $this->code,
295 implode("|", $modes),
296 $levels[$this->level],
297 $this->error_message_prefix,
298 $this->userinfo
299 );
300 }
301 }
302