Subversion Repositories Applications.gtt

Rev

Rev 94 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
1
<?php
1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
2
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
3
/**
3
/**
4
 * PEAR_Exception
4
 * PEAR_Exception
5
 *
5
 *
6
 * PHP versions 4 and 5
6
 * PHP versions 4 and 5
7
 *
7
 *
8
 * LICENSE: This source file is subject to version 3.0 of the PHP license
-
 
9
 * that is available through the world-wide-web at the following URI:
-
 
10
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
-
 
11
 * the PHP License and are unable to obtain it through the web, please
-
 
12
 * send a note to license@php.net so we can mail you a copy immediately.
-
 
13
 *
-
 
14
 * @category   pear
8
 * @category   pear
15
 * @package    PEAR
9
 * @package    PEAR
16
 * @author     Tomas V. V. Cox <cox@idecnet.com>
10
 * @author     Tomas V. V. Cox <cox@idecnet.com>
17
 * @author     Hans Lellelid <hans@velum.net>
11
 * @author     Hans Lellelid <hans@velum.net>
18
 * @author     Bertrand Mansion <bmansion@mamasam.com>
12
 * @author     Bertrand Mansion <bmansion@mamasam.com>
19
 * @author     Greg Beaver <cellog@php.net>
13
 * @author     Greg Beaver <cellog@php.net>
20
 * @copyright  1997-2006 The PHP Group
14
 * @copyright  1997-2009 The Authors
21
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
15
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
22
 * @version    CVS: $Id: Exception.php,v 1.26 2006/10/30 03:47:48 cellog Exp $
-
 
23
 * @link       http://pear.php.net/package/PEAR
16
 * @link       http://pear.php.net/package/PEAR
24
 * @since      File available since Release 1.3.3
17
 * @since      File available since Release 1.3.3
25
 */
18
 */
26
 
19
 
27
 
20
 
28
/**
21
/**
29
 * Base PEAR_Exception Class
22
 * Base PEAR_Exception Class
30
 *
23
 *
31
 * 1) Features:
24
 * 1) Features:
32
 *
25
 *
33
 * - Nestable exceptions (throw new PEAR_Exception($msg, $prev_exception))
26
 * - Nestable exceptions (throw new PEAR_Exception($msg, $prev_exception))
34
 * - Definable triggers, shot when exceptions occur
27
 * - Definable triggers, shot when exceptions occur
35
 * - Pretty and informative error messages
28
 * - Pretty and informative error messages
36
 * - Added more context info available (like class, method or cause)
29
 * - Added more context info available (like class, method or cause)
37
 * - cause can be a PEAR_Exception or an array of mixed
30
 * - cause can be a PEAR_Exception or an array of mixed
38
 *   PEAR_Exceptions/PEAR_ErrorStack warnings
31
 *   PEAR_Exceptions/PEAR_ErrorStack warnings
39
 * - callbacks for specific exception classes and their children
32
 * - callbacks for specific exception classes and their children
40
 *
33
 *
41
 * 2) Ideas:
34
 * 2) Ideas:
42
 *
35
 *
43
 * - Maybe a way to define a 'template' for the output
36
 * - Maybe a way to define a 'template' for the output
44
 *
37
 *
45
 * 3) Inherited properties from PHP Exception Class:
38
 * 3) Inherited properties from PHP Exception Class:
46
 *
39
 *
47
 * protected $message
40
 * protected $message
48
 * protected $code
41
 * protected $code
49
 * protected $line
42
 * protected $line
50
 * protected $file
43
 * protected $file
51
 * private   $trace
44
 * private   $trace
52
 *
45
 *
53
 * 4) Inherited methods from PHP Exception Class:
46
 * 4) Inherited methods from PHP Exception Class:
54
 *
47
 *
55
 * __clone
48
 * __clone
56
 * __construct
49
 * __construct
57
 * getMessage
50
 * getMessage
58
 * getCode
51
 * getCode
59
 * getFile
52
 * getFile
60
 * getLine
53
 * getLine
61
 * getTraceSafe
54
 * getTraceSafe
62
 * getTraceSafeAsString
55
 * getTraceSafeAsString
63
 * __toString
56
 * __toString
64
 *
57
 *
65
 * 5) Usage example
58
 * 5) Usage example
66
 *
59
 *
67
 * <code>
60
 * <code>
68
 *  require_once 'PEAR/Exception.php';
61
 *  require_once 'PEAR/Exception.php';
69
 *
62
 *
70
 *  class Test {
63
 *  class Test {
71
 *     function foo() {
64
 *     function foo() {
72
 *         throw new PEAR_Exception('Error Message', ERROR_CODE);
65
 *         throw new PEAR_Exception('Error Message', ERROR_CODE);
73
 *     }
66
 *     }
74
 *  }
67
 *  }
75
 *
68
 *
76
 *  function myLogger($pear_exception) {
69
 *  function myLogger($pear_exception) {
77
 *     echo $pear_exception->getMessage();
70
 *     echo $pear_exception->getMessage();
78
 *  }
71
 *  }
79
 *  // each time a exception is thrown the 'myLogger' will be called
72
 *  // each time a exception is thrown the 'myLogger' will be called
80
 *  // (its use is completely optional)
73
 *  // (its use is completely optional)
81
 *  PEAR_Exception::addObserver('myLogger');
74
 *  PEAR_Exception::addObserver('myLogger');
82
 *  $test = new Test;
75
 *  $test = new Test;
83
 *  try {
76
 *  try {
84
 *     $test->foo();
77
 *     $test->foo();
85
 *  } catch (PEAR_Exception $e) {
78
 *  } catch (PEAR_Exception $e) {
86
 *     print $e;
79
 *     print $e;
87
 *  }
80
 *  }
88
 * </code>
81
 * </code>
89
 *
82
 *
90
 * @category   pear
83
 * @category   pear
91
 * @package    PEAR
84
 * @package    PEAR
92
 * @author     Tomas V.V.Cox <cox@idecnet.com>
85
 * @author     Tomas V.V.Cox <cox@idecnet.com>
93
 * @author     Hans Lellelid <hans@velum.net>
86
 * @author     Hans Lellelid <hans@velum.net>
94
 * @author     Bertrand Mansion <bmansion@mamasam.com>
87
 * @author     Bertrand Mansion <bmansion@mamasam.com>
95
 * @author     Greg Beaver <cellog@php.net>
88
 * @author     Greg Beaver <cellog@php.net>
96
 * @copyright  1997-2006 The PHP Group
89
 * @copyright  1997-2009 The Authors
97
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
90
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
98
 * @version    Release: 1.5.1
91
 * @version    Release: 1.10.1
99
 * @link       http://pear.php.net/package/PEAR
92
 * @link       http://pear.php.net/package/PEAR
100
 * @since      Class available since Release 1.3.3
93
 * @since      Class available since Release 1.3.3
101
 *
94
 *
102
 */
95
 */
103
class PEAR_Exception extends Exception
96
class PEAR_Exception extends Exception
104
{
97
{
105
    const OBSERVER_PRINT = -2;
98
    const OBSERVER_PRINT = -2;
106
    const OBSERVER_TRIGGER = -4;
99
    const OBSERVER_TRIGGER = -4;
107
    const OBSERVER_DIE = -8;
100
    const OBSERVER_DIE = -8;
108
    protected $cause;
101
    protected $cause;
109
    private static $_observers = array();
102
    private static $_observers = array();
110
    private static $_uniqueid = 0;
103
    private static $_uniqueid = 0;
111
    private $_trace;
104
    private $_trace;
112
 
105
 
113
    /**
106
    /**
114
     * Supported signatures:
107
     * Supported signatures:
115
     *  - PEAR_Exception(string $message);
108
     *  - PEAR_Exception(string $message);
116
     *  - PEAR_Exception(string $message, int $code);
109
     *  - PEAR_Exception(string $message, int $code);
117
     *  - PEAR_Exception(string $message, Exception $cause);
110
     *  - PEAR_Exception(string $message, Exception $cause);
118
     *  - PEAR_Exception(string $message, Exception $cause, int $code);
111
     *  - PEAR_Exception(string $message, Exception $cause, int $code);
119
     *  - PEAR_Exception(string $message, PEAR_Error $cause);
112
     *  - PEAR_Exception(string $message, PEAR_Error $cause);
120
     *  - PEAR_Exception(string $message, PEAR_Error $cause, int $code);
113
     *  - PEAR_Exception(string $message, PEAR_Error $cause, int $code);
121
     *  - PEAR_Exception(string $message, array $causes);
114
     *  - PEAR_Exception(string $message, array $causes);
122
     *  - PEAR_Exception(string $message, array $causes, int $code);
115
     *  - PEAR_Exception(string $message, array $causes, int $code);
123
     * @param string exception message
116
     * @param string exception message
124
     * @param int|Exception|PEAR_Error|array|null exception cause
117
     * @param int|Exception|PEAR_Error|array|null exception cause
125
     * @param int|null exception code or null
118
     * @param int|null exception code or null
126
     */
119
     */
127
    public function __construct($message, $p2 = null, $p3 = null)
120
    public function __construct($message, $p2 = null, $p3 = null)
128
    {
121
    {
129
        if (is_int($p2)) {
122
        if (is_int($p2)) {
130
            $code = $p2;
123
            $code = $p2;
131
            $this->cause = null;
124
            $this->cause = null;
132
        } elseif (is_object($p2) || is_array($p2)) {
125
        } elseif (is_object($p2) || is_array($p2)) {
133
            // using is_object allows both Exception and PEAR_Error
126
            // using is_object allows both Exception and PEAR_Error
134
            if (is_object($p2) && !($p2 instanceof Exception)) {
127
            if (is_object($p2) && !($p2 instanceof Exception)) {
135
                if (!class_exists('PEAR_Error') || !($p2 instanceof PEAR_Error)) {
128
                if (!class_exists('PEAR_Error') || !($p2 instanceof PEAR_Error)) {
136
                    throw new PEAR_Exception('exception cause must be Exception, ' .
129
                    throw new PEAR_Exception('exception cause must be Exception, ' .
137
                        'array, or PEAR_Error');
130
                        'array, or PEAR_Error');
138
                }
131
                }
139
            }
132
            }
140
            $code = $p3;
133
            $code = $p3;
141
            if (is_array($p2) && isset($p2['message'])) {
134
            if (is_array($p2) && isset($p2['message'])) {
142
                // fix potential problem of passing in a single warning
135
                // fix potential problem of passing in a single warning
143
                $p2 = array($p2);
136
                $p2 = array($p2);
144
            }
137
            }
145
            $this->cause = $p2;
138
            $this->cause = $p2;
146
        } else {
139
        } else {
147
            $code = null;
140
            $code = null;
148
            $this->cause = null;
141
            $this->cause = null;
149
        }
142
        }
150
        parent::__construct($message, $code);
143
        parent::__construct($message, $code);
151
        $this->signal();
144
        $this->signal();
152
    }
145
    }
153
 
146
 
154
    /**
147
    /**
155
     * @param mixed $callback  - A valid php callback, see php func is_callable()
148
     * @param mixed $callback  - A valid php callback, see php func is_callable()
156
     *                         - A PEAR_Exception::OBSERVER_* constant
149
     *                         - A PEAR_Exception::OBSERVER_* constant
157
     *                         - An array(const PEAR_Exception::OBSERVER_*,
150
     *                         - An array(const PEAR_Exception::OBSERVER_*,
158
     *                           mixed $options)
151
     *                           mixed $options)
159
     * @param string $label    The name of the observer. Use this if you want
152
     * @param string $label    The name of the observer. Use this if you want
160
     *                         to remove it later with removeObserver()
153
     *                         to remove it later with removeObserver()
161
     */
154
     */
162
    public static function addObserver($callback, $label = 'default')
155
    public static function addObserver($callback, $label = 'default')
163
    {
156
    {
164
        self::$_observers[$label] = $callback;
157
        self::$_observers[$label] = $callback;
165
    }
158
    }
166
 
159
 
167
    public static function removeObserver($label = 'default')
160
    public static function removeObserver($label = 'default')
168
    {
161
    {
169
        unset(self::$_observers[$label]);
162
        unset(self::$_observers[$label]);
170
    }
163
    }
171
 
164
 
172
    /**
165
    /**
173
     * @return int unique identifier for an observer
166
     * @return int unique identifier for an observer
174
     */
167
     */
175
    public static function getUniqueId()
168
    public static function getUniqueId()
176
    {
169
    {
177
        return self::$_uniqueid++;
170
        return self::$_uniqueid++;
178
    }
171
    }
179
 
172
 
180
    private function signal()
173
    private function signal()
181
    {
174
    {
182
        foreach (self::$_observers as $func) {
175
        foreach (self::$_observers as $func) {
183
            if (is_callable($func)) {
176
            if (is_callable($func)) {
184
                call_user_func($func, $this);
177
                call_user_func($func, $this);
185
                continue;
178
                continue;
186
            }
179
            }
187
            settype($func, 'array');
180
            settype($func, 'array');
188
            switch ($func[0]) {
181
            switch ($func[0]) {
189
                case self::OBSERVER_PRINT :
182
                case self::OBSERVER_PRINT :
190
                    $f = (isset($func[1])) ? $func[1] : '%s';
183
                    $f = (isset($func[1])) ? $func[1] : '%s';
191
                    printf($f, $this->getMessage());
184
                    printf($f, $this->getMessage());
192
                    break;
185
                    break;
193
                case self::OBSERVER_TRIGGER :
186
                case self::OBSERVER_TRIGGER :
194
                    $f = (isset($func[1])) ? $func[1] : E_USER_NOTICE;
187
                    $f = (isset($func[1])) ? $func[1] : E_USER_NOTICE;
195
                    trigger_error($this->getMessage(), $f);
188
                    trigger_error($this->getMessage(), $f);
196
                    break;
189
                    break;
197
                case self::OBSERVER_DIE :
190
                case self::OBSERVER_DIE :
198
                    $f = (isset($func[1])) ? $func[1] : '%s';
191
                    $f = (isset($func[1])) ? $func[1] : '%s';
199
                    die(printf($f, $this->getMessage()));
192
                    die(printf($f, $this->getMessage()));
200
                    break;
193
                    break;
201
                default:
194
                default:
202
                    trigger_error('invalid observer type', E_USER_WARNING);
195
                    trigger_error('invalid observer type', E_USER_WARNING);
203
            }
196
            }
204
        }
197
        }
205
    }
198
    }
206
 
199
 
207
    /**
200
    /**
208
     * Return specific error information that can be used for more detailed
201
     * Return specific error information that can be used for more detailed
209
     * error messages or translation.
202
     * error messages or translation.
210
     *
203
     *
211
     * This method may be overridden in child exception classes in order
204
     * This method may be overridden in child exception classes in order
212
     * to add functionality not present in PEAR_Exception and is a placeholder
205
     * to add functionality not present in PEAR_Exception and is a placeholder
213
     * to define API
206
     * to define API
214
     *
207
     *
215
     * The returned array must be an associative array of parameter => value like so:
208
     * The returned array must be an associative array of parameter => value like so:
216
     * <pre>
209
     * <pre>
217
     * array('name' => $name, 'context' => array(...))
210
     * array('name' => $name, 'context' => array(...))
218
     * </pre>
211
     * </pre>
219
     * @return array
212
     * @return array
220
     */
213
     */
221
    public function getErrorData()
214
    public function getErrorData()
222
    {
215
    {
223
        return array();
216
        return array();
224
    }
217
    }
225
 
218
 
226
    /**
219
    /**
227
     * Returns the exception that caused this exception to be thrown
220
     * Returns the exception that caused this exception to be thrown
228
     * @access public
221
     * @access public
229
     * @return Exception|array The context of the exception
222
     * @return Exception|array The context of the exception
230
     */
223
     */
231
    public function getCause()
224
    public function getCause()
232
    {
225
    {
233
        return $this->cause;
226
        return $this->cause;
234
    }
227
    }
235
 
228
 
236
    /**
229
    /**
237
     * Function must be public to call on caused exceptions
230
     * Function must be public to call on caused exceptions
238
     * @param array
231
     * @param array
239
     */
232
     */
240
    public function getCauseMessage(&$causes)
233
    public function getCauseMessage(&$causes)
241
    {
234
    {
242
        $trace = $this->getTraceSafe();
235
        $trace = $this->getTraceSafe();
243
        $cause = array('class'   => get_class($this),
236
        $cause = array('class'   => get_class($this),
244
                       'message' => $this->message,
237
                       'message' => $this->message,
245
                       'file' => 'unknown',
238
                       'file' => 'unknown',
246
                       'line' => 'unknown');
239
                       'line' => 'unknown');
247
        if (isset($trace[0])) {
240
        if (isset($trace[0])) {
248
            if (isset($trace[0]['file'])) {
241
            if (isset($trace[0]['file'])) {
249
                $cause['file'] = $trace[0]['file'];
242
                $cause['file'] = $trace[0]['file'];
250
                $cause['line'] = $trace[0]['line'];
243
                $cause['line'] = $trace[0]['line'];
251
            }
244
            }
252
        }
245
        }
253
        $causes[] = $cause;
246
        $causes[] = $cause;
254
        if ($this->cause instanceof PEAR_Exception) {
247
        if ($this->cause instanceof PEAR_Exception) {
255
            $this->cause->getCauseMessage($causes);
248
            $this->cause->getCauseMessage($causes);
256
        } elseif ($this->cause instanceof Exception) {
249
        } elseif ($this->cause instanceof Exception) {
257
            $causes[] = array('class'   => get_class($this->cause),
250
            $causes[] = array('class'   => get_class($this->cause),
258
                              'message' => $this->cause->getMessage(),
251
                              'message' => $this->cause->getMessage(),
259
                              'file' => $this->cause->getFile(),
252
                              'file' => $this->cause->getFile(),
260
                              'line' => $this->cause->getLine());
253
                              'line' => $this->cause->getLine());
261
        } elseif (class_exists('PEAR_Error') && $this->cause instanceof PEAR_Error) {
254
        } elseif (class_exists('PEAR_Error') && $this->cause instanceof PEAR_Error) {
262
            $causes[] = array('class' => get_class($this->cause),
255
            $causes[] = array('class' => get_class($this->cause),
263
                              'message' => $this->cause->getMessage());
256
                              'message' => $this->cause->getMessage(),
-
 
257
                              'file' => 'unknown',
-
 
258
                              'line' => 'unknown');
264
        } elseif (is_array($this->cause)) {
259
        } elseif (is_array($this->cause)) {
265
            foreach ($this->cause as $cause) {
260
            foreach ($this->cause as $cause) {
266
                if ($cause instanceof PEAR_Exception) {
261
                if ($cause instanceof PEAR_Exception) {
267
                    $cause->getCauseMessage($causes);
262
                    $cause->getCauseMessage($causes);
268
                } elseif ($cause instanceof Exception) {
263
                } elseif ($cause instanceof Exception) {
269
                    $causes[] = array('class'   => get_class($cause),
264
                    $causes[] = array('class'   => get_class($cause),
270
                                   'message' => $cause->getMessage(),
265
                                   'message' => $cause->getMessage(),
271
                                   'file' => $cause->getFile(),
266
                                   'file' => $cause->getFile(),
272
                                   'line' => $cause->getLine());
267
                                   'line' => $cause->getLine());
273
                } elseif (class_exists('PEAR_Error') && $cause instanceof PEAR_Error) {
268
                } elseif (class_exists('PEAR_Error') && $cause instanceof PEAR_Error) {
274
                    $causes[] = array('class' => get_class($cause),
269
                    $causes[] = array('class' => get_class($cause),
275
                                      'message' => $cause->getMessage());
270
                                      'message' => $cause->getMessage(),
-
 
271
                                      'file' => 'unknown',
-
 
272
                                      'line' => 'unknown');
276
                } elseif (is_array($cause) && isset($cause['message'])) {
273
                } elseif (is_array($cause) && isset($cause['message'])) {
277
                    // PEAR_ErrorStack warning
274
                    // PEAR_ErrorStack warning
278
                    $causes[] = array(
275
                    $causes[] = array(
279
                        'class' => $cause['package'],
276
                        'class' => $cause['package'],
280
                        'message' => $cause['message'],
277
                        'message' => $cause['message'],
281
                        'file' => isset($cause['context']['file']) ?
278
                        'file' => isset($cause['context']['file']) ?
282
                                            $cause['context']['file'] :
279
                                            $cause['context']['file'] :
283
                                            'unknown',
280
                                            'unknown',
284
                        'line' => isset($cause['context']['line']) ?
281
                        'line' => isset($cause['context']['line']) ?
285
                                            $cause['context']['line'] :
282
                                            $cause['context']['line'] :
286
                                            'unknown',
283
                                            'unknown',
287
                    );
284
                    );
288
                }
285
                }
289
            }
286
            }
290
        }
287
        }
291
    }
288
    }
292
 
289
 
293
    public function getTraceSafe()
290
    public function getTraceSafe()
294
    {   
291
    {
295
        if (!isset($this->_trace)) {
292
        if (!isset($this->_trace)) {
296
            $this->_trace = $this->getTrace();
293
            $this->_trace = $this->getTrace();
297
            if (empty($this->_trace)) {
294
            if (empty($this->_trace)) {
298
                $backtrace = debug_backtrace();
295
                $backtrace = debug_backtrace();
299
                $this->_trace = array($backtrace[count($backtrace)-1]);
296
                $this->_trace = array($backtrace[count($backtrace)-1]);
300
            }
297
            }
301
        }
298
        }
302
        return $this->_trace;
299
        return $this->_trace;
303
    }
300
    }
304
 
301
 
305
    public function getErrorClass()
302
    public function getErrorClass()
306
    {
303
    {
307
        $trace = $this->getTraceSafe();
304
        $trace = $this->getTraceSafe();
308
        return $trace[0]['class'];
305
        return $trace[0]['class'];
309
    }
306
    }
310
 
307
 
311
    public function getErrorMethod()
308
    public function getErrorMethod()
312
    {
309
    {
313
        $trace = $this->getTraceSafe();
310
        $trace = $this->getTraceSafe();
314
        return $trace[0]['function'];
311
        return $trace[0]['function'];
315
    }
312
    }
316
 
313
 
317
    public function __toString()
314
    public function __toString()
318
    {
315
    {
319
        if (isset($_SERVER['REQUEST_URI'])) {
316
        if (isset($_SERVER['REQUEST_URI'])) {
320
            return $this->toHtml();
317
            return $this->toHtml();
321
        }
318
        }
322
        return $this->toText();
319
        return $this->toText();
323
    }
320
    }
324
 
321
 
325
    public function toHtml()
322
    public function toHtml()
326
    {
323
    {
327
        $trace = $this->getTraceSafe();
324
        $trace = $this->getTraceSafe();
328
        $causes = array();
325
        $causes = array();
329
        $this->getCauseMessage($causes);
326
        $this->getCauseMessage($causes);
330
        $html =  '<table border="1" cellspacing="0">' . "\n";
327
        $html =  '<table style="border: 1px" cellspacing="0">' . "\n";
331
        foreach ($causes as $i => $cause) {
328
        foreach ($causes as $i => $cause) {
332
            $html .= '<tr><td colspan="3" bgcolor="#ff9999">'
329
            $html .= '<tr><td colspan="3" style="background: #ff9999">'
333
               . str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: '
330
               . str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: '
334
               . htmlspecialchars($cause['message']) . ' in <b>' . $cause['file'] . '</b> '
331
               . htmlspecialchars($cause['message']) . ' in <b>' . $cause['file'] . '</b> '
335
               . 'on line <b>' . $cause['line'] . '</b>'
332
               . 'on line <b>' . $cause['line'] . '</b>'
336
               . "</td></tr>\n";
333
               . "</td></tr>\n";
337
        }
334
        }
338
        $html .= '<tr><td colspan="3" bgcolor="#aaaaaa" align="center"><b>Exception trace</b></td></tr>' . "\n"
335
        $html .= '<tr><td colspan="3" style="background-color: #aaaaaa; text-align: center; font-weight: bold;">Exception trace</td></tr>' . "\n"
339
               . '<tr><td align="center" bgcolor="#cccccc" width="20"><b>#</b></td>'
336
               . '<tr><td style="text-align: center; background: #cccccc; width:20px; font-weight: bold;">#</td>'
340
               . '<td align="center" bgcolor="#cccccc"><b>Function</b></td>'
337
               . '<td style="text-align: center; background: #cccccc; font-weight: bold;">Function</td>'
341
               . '<td align="center" bgcolor="#cccccc"><b>Location</b></td></tr>' . "\n";
338
               . '<td style="text-align: center; background: #cccccc; font-weight: bold;">Location</td></tr>' . "\n";
342
 
339
 
343
        foreach ($trace as $k => $v) {
340
        foreach ($trace as $k => $v) {
344
            $html .= '<tr><td align="center">' . $k . '</td>'
341
            $html .= '<tr><td style="text-align: center;">' . $k . '</td>'
345
                   . '<td>';
342
                   . '<td>';
346
            if (!empty($v['class'])) {
343
            if (!empty($v['class'])) {
347
                $html .= $v['class'] . $v['type'];
344
                $html .= $v['class'] . $v['type'];
348
            }
345
            }
349
            $html .= $v['function'];
346
            $html .= $v['function'];
350
            $args = array();
347
            $args = array();
351
            if (!empty($v['args'])) {
348
            if (!empty($v['args'])) {
352
                foreach ($v['args'] as $arg) {
349
                foreach ($v['args'] as $arg) {
353
                    if (is_null($arg)) $args[] = 'null';
350
                    if (is_null($arg)) $args[] = 'null';
354
                    elseif (is_array($arg)) $args[] = 'Array';
351
                    elseif (is_array($arg)) $args[] = 'Array';
355
                    elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')';
352
                    elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')';
356
                    elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false';
353
                    elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false';
357
                    elseif (is_int($arg) || is_double($arg)) $args[] = $arg;
354
                    elseif (is_int($arg) || is_double($arg)) $args[] = $arg;
358
                    else {
355
                    else {
359
                        $arg = (string)$arg;
356
                        $arg = (string)$arg;
360
                        $str = htmlspecialchars(substr($arg, 0, 16));
357
                        $str = htmlspecialchars(substr($arg, 0, 16));
361
                        if (strlen($arg) > 16) $str .= '&hellip;';
358
                        if (strlen($arg) > 16) $str .= '&hellip;';
362
                        $args[] = "'" . $str . "'";
359
                        $args[] = "'" . $str . "'";
363
                    }
360
                    }
364
                }
361
                }
365
            }
362
            }
366
            $html .= '(' . implode(', ',$args) . ')'
363
            $html .= '(' . implode(', ',$args) . ')'
367
                   . '</td>'
364
                   . '</td>'
368
                   . '<td>' . (isset($v['file']) ? $v['file'] : 'unknown')
365
                   . '<td>' . (isset($v['file']) ? $v['file'] : 'unknown')
369
                   . ':' . (isset($v['line']) ? $v['line'] : 'unknown')
366
                   . ':' . (isset($v['line']) ? $v['line'] : 'unknown')
370
                   . '</td></tr>' . "\n";
367
                   . '</td></tr>' . "\n";
371
        }
368
        }
372
        $html .= '<tr><td align="center">' . ($k+1) . '</td>'
369
        $html .= '<tr><td style="text-align: center;">' . ($k+1) . '</td>'
373
               . '<td>{main}</td>'
370
               . '<td>{main}</td>'
374
               . '<td>&nbsp;</td></tr>' . "\n"
371
               . '<td>&nbsp;</td></tr>' . "\n"
375
               . '</table>';
372
               . '</table>';
376
        return $html;
373
        return $html;
377
    }
374
    }
378
 
375
 
379
    public function toText()
376
    public function toText()
380
    {
377
    {
381
        $causes = array();
378
        $causes = array();
382
        $this->getCauseMessage($causes);
379
        $this->getCauseMessage($causes);
383
        $causeMsg = '';
380
        $causeMsg = '';
384
        foreach ($causes as $i => $cause) {
381
        foreach ($causes as $i => $cause) {
385
            $causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': '
382
            $causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': '
386
                   . $cause['message'] . ' in ' . $cause['file']
383
                   . $cause['message'] . ' in ' . $cause['file']
387
                   . ' on line ' . $cause['line'] . "\n";
384
                   . ' on line ' . $cause['line'] . "\n";
388
        }
385
        }
389
        return $causeMsg . $this->getTraceAsString();
386
        return $causeMsg . $this->getTraceAsString();
390
    }
387
    }
391
}
-
 
392
 
-
 
393
?>
-
 
394
388
}
-
 
389
395
390