Subversion Repositories Applications.gtt

Rev

Rev 94 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 187
Line 4... Line 4...
4
 *
4
 *
5
 * PEAR class and PEAR_Error class
5
 * PEAR class and PEAR_Error class
6
 *
6
 *
7
 * PHP versions 4 and 5
7
 * PHP versions 4 and 5
8
 *
8
 *
9
 * LICENSE: This source file is subject to version 3.0 of the PHP license
-
 
10
 * that is available through the world-wide-web at the following URI:
-
 
11
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
-
 
12
 * the PHP License and are unable to obtain it through the web, please
-
 
13
 * send a note to license@php.net so we can mail you a copy immediately.
-
 
14
 *
-
 
15
 * @category   pear
9
 * @category   pear
16
 * @package    PEAR
10
 * @package    PEAR
17
 * @author     Sterling Hughes <sterling@php.net>
11
 * @author     Sterling Hughes <sterling@php.net>
18
 * @author     Stig Bakken <ssb@php.net>
12
 * @author     Stig Bakken <ssb@php.net>
19
 * @author     Tomas V.V.Cox <cox@idecnet.com>
13
 * @author     Tomas V.V.Cox <cox@idecnet.com>
20
 * @author     Greg Beaver <cellog@php.net>
14
 * @author     Greg Beaver <cellog@php.net>
21
 * @copyright  1997-2006 The PHP Group
15
 * @copyright  1997-2010 The Authors
22
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
16
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
23
 * @version    CVS: $Id: PEAR.php,v 1.101 2006/04/25 02:41:03 cellog Exp $
-
 
24
 * @link       http://pear.php.net/package/PEAR
17
 * @link       http://pear.php.net/package/PEAR
25
 * @since      File available since Release 0.1
18
 * @since      File available since Release 0.1
26
 */
19
 */
Line 27... Line 20...
27
 
20
 
Line 37... Line 30...
37
 * WARNING: obsolete
30
 * WARNING: obsolete
38
 * @deprecated
31
 * @deprecated
39
 */
32
 */
40
define('PEAR_ERROR_EXCEPTION', 32);
33
define('PEAR_ERROR_EXCEPTION', 32);
41
/**#@-*/
34
/**#@-*/
42
define('PEAR_ZE2', (function_exists('version_compare') &&
-
 
43
                    version_compare(zend_version(), "2-dev", "ge")));
-
 
Line 44... Line 35...
44
 
35
 
45
if (substr(PHP_OS, 0, 3) == 'WIN') {
36
if (substr(PHP_OS, 0, 3) == 'WIN') {
46
    define('OS_WINDOWS', true);
37
    define('OS_WINDOWS', true);
47
    define('OS_UNIX',    false);
38
    define('OS_UNIX',    false);
Line 50... Line 41...
50
    define('OS_WINDOWS', false);
41
    define('OS_WINDOWS', false);
51
    define('OS_UNIX',    true);
42
    define('OS_UNIX',    true);
52
    define('PEAR_OS',    'Unix'); // blatant assumption
43
    define('PEAR_OS',    'Unix'); // blatant assumption
53
}
44
}
Line 54... Line -...
54
 
-
 
55
// instant backwards compatibility
-
 
56
if (!defined('PATH_SEPARATOR')) {
-
 
57
    if (OS_WINDOWS) {
-
 
58
        define('PATH_SEPARATOR', ';');
-
 
59
    } else {
-
 
60
        define('PATH_SEPARATOR', ':');
-
 
61
    }
-
 
62
}
-
 
63
 
45
 
64
$GLOBALS['_PEAR_default_error_mode']     = PEAR_ERROR_RETURN;
46
$GLOBALS['_PEAR_default_error_mode']     = PEAR_ERROR_RETURN;
65
$GLOBALS['_PEAR_default_error_options']  = E_USER_NOTICE;
47
$GLOBALS['_PEAR_default_error_options']  = E_USER_NOTICE;
66
$GLOBALS['_PEAR_destructor_object_list'] = array();
48
$GLOBALS['_PEAR_destructor_object_list'] = array();
67
$GLOBALS['_PEAR_shutdown_funcs']         = array();
49
$GLOBALS['_PEAR_shutdown_funcs']         = array();
Line 90... Line 72...
90
 * @package    PEAR
72
 * @package    PEAR
91
 * @author     Stig Bakken <ssb@php.net>
73
 * @author     Stig Bakken <ssb@php.net>
92
 * @author     Tomas V.V. Cox <cox@idecnet.com>
74
 * @author     Tomas V.V. Cox <cox@idecnet.com>
93
 * @author     Greg Beaver <cellog@php.net>
75
 * @author     Greg Beaver <cellog@php.net>
94
 * @copyright  1997-2006 The PHP Group
76
 * @copyright  1997-2006 The PHP Group
95
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
77
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
96
 * @version    Release: 1.5.1
78
 * @version    Release: 1.10.1
97
 * @link       http://pear.php.net/package/PEAR
79
 * @link       http://pear.php.net/package/PEAR
98
 * @see        PEAR_Error
80
 * @see        PEAR_Error
99
 * @since      Class available since PHP 4.0.2
81
 * @since      Class available since PHP 4.0.2
100
 * @link        http://pear.php.net/manual/en/core.pear.php#core.pear.pear
82
 * @link        http://pear.php.net/manual/en/core.pear.php#core.pear.pear
101
 */
83
 */
102
class PEAR
84
class PEAR
103
{
85
{
104
    // {{{ properties
-
 
105
 
-
 
106
    /**
86
    /**
107
     * Whether to enable internal debug messages.
87
     * Whether to enable internal debug messages.
108
     *
88
     *
109
     * @var     bool
89
     * @var     bool
110
     * @access  private
90
     * @access  private
Line 151... Line 131...
151
     * @var     array
131
     * @var     array
152
     * @access  private
132
     * @access  private
153
     */
133
     */
154
    var $_expected_errors = array();
134
    var $_expected_errors = array();
Line 155... Line 135...
155
 
135
 
-
 
136
    /**
-
 
137
     * List of methods that can be called both statically and non-statically.
156
    // }}}
138
     * @var array
-
 
139
     */
-
 
140
    protected static $bivalentMethods = array(
-
 
141
        'setErrorHandling' => true,
157
 
142
        'raiseError' => true,
-
 
143
        'throwError' => true,
-
 
144
        'pushErrorHandling' => true,
-
 
145
        'popErrorHandling' => true,
Line 158... Line 146...
158
    // {{{ constructor
146
    );
159
 
147
 
160
    /**
148
    /**
161
     * Constructor.  Registers this object in
149
     * Constructor.  Registers this object in
Line 165... Line 153...
165
     * @param string $error_class  (optional) which class to use for
153
     * @param string $error_class  (optional) which class to use for
166
     *        error objects, defaults to PEAR_Error.
154
     *        error objects, defaults to PEAR_Error.
167
     * @access public
155
     * @access public
168
     * @return void
156
     * @return void
169
     */
157
     */
170
    function PEAR($error_class = null)
158
    function __construct($error_class = null)
171
    {
159
    {
172
        $classname = strtolower(get_class($this));
160
        $classname = strtolower(get_class($this));
173
        if ($this->_debug) {
161
        if ($this->_debug) {
174
            print "PEAR constructor called, class=$classname\n";
162
            print "PEAR constructor called, class=$classname\n";
175
        }
163
        }
-
 
164
 
176
        if ($error_class !== null) {
165
        if ($error_class !== null) {
177
            $this->_error_class = $error_class;
166
            $this->_error_class = $error_class;
178
        }
167
        }
-
 
168
 
179
        while ($classname && strcasecmp($classname, "pear")) {
169
        while ($classname && strcasecmp($classname, "pear")) {
180
            $destructor = "_$classname";
170
            $destructor = "_$classname";
181
            if (method_exists($this, $destructor)) {
171
            if (method_exists($this, $destructor)) {
182
                global $_PEAR_destructor_object_list;
172
                global $_PEAR_destructor_object_list;
183
                $_PEAR_destructor_object_list[] = &$this;
173
                $_PEAR_destructor_object_list[] = &$this;
Line 190... Line 180...
190
                $classname = get_parent_class($classname);
180
                $classname = get_parent_class($classname);
191
            }
181
            }
192
        }
182
        }
193
    }
183
    }
Line 194... Line 184...
194
 
184
 
-
 
185
    /**
-
 
186
     * Only here for backwards compatibility.
-
 
187
     * E.g. Archive_Tar calls $this->PEAR() in its constructor.
-
 
188
     *
-
 
189
     * @param string $error_class Which class to use for error objects,
-
 
190
     *                            defaults to PEAR_Error.
-
 
191
     */
-
 
192
    public function PEAR($error_class = null)
195
    // }}}
193
    {
-
 
194
        self::__construct($error_class);
Line 196... Line 195...
196
    // {{{ destructor
195
    }
197
 
196
 
198
    /**
197
    /**
199
     * Destructor (the emulated type of...).  Does nothing right now,
198
     * Destructor (the emulated type of...).  Does nothing right now,
Line 210... Line 209...
210
        if ($this->_debug) {
209
        if ($this->_debug) {
211
            printf("PEAR destructor called, class=%s\n", strtolower(get_class($this)));
210
            printf("PEAR destructor called, class=%s\n", strtolower(get_class($this)));
212
        }
211
        }
213
    }
212
    }
Line -... Line 213...
-
 
213
 
-
 
214
    public function __call($method, $arguments)
-
 
215
    {
-
 
216
        if (!isset(self::$bivalentMethods[$method])) {
-
 
217
            trigger_error(
-
 
218
                'Call to undefined method PEAR::' . $method . '()', E_USER_ERROR
214
 
219
            );
-
 
220
        }
-
 
221
        return call_user_func_array(
-
 
222
            array(get_class(), '_' . $method),
-
 
223
            array_merge(array($this), $arguments)
-
 
224
        );
-
 
225
    }
-
 
226
 
-
 
227
    public static function __callStatic($method, $arguments)
-
 
228
    {
215
    // }}}
229
        if (!isset(self::$bivalentMethods[$method])) {
-
 
230
            trigger_error(
-
 
231
                'Call to undefined method PEAR::' . $method . '()', E_USER_ERROR
-
 
232
            );
-
 
233
        }
-
 
234
        return call_user_func_array(
-
 
235
            array(get_class(), '_' . $method),
-
 
236
            array_merge(array(null), $arguments)
-
 
237
        );
Line 216... Line 238...
216
    // {{{ getStaticProperty()
238
    }
217
 
239
 
218
    /**
240
    /**
219
    * If you have a class that's mostly/entirely static, and you need static
241
    * If you have a class that's mostly/entirely static, and you need static
220
    * properties, you can use this method to simulate them. Eg. in your method(s)
242
    * properties, you can use this method to simulate them. Eg. in your method(s)
221
    * do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar');
243
    * do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar');
222
    * You MUST use a reference, or they will not persist!
-
 
223
    *
244
    * You MUST use a reference, or they will not persist!
224
    * @access public
245
    *
225
    * @param  string $class  The calling classname, to prevent clashes
246
    * @param  string $class  The calling classname, to prevent clashes
226
    * @param  string $var    The variable to retrieve.
247
    * @param  string $var    The variable to retrieve.
227
    * @return mixed   A reference to the variable. If not set it will be
248
    * @return mixed   A reference to the variable. If not set it will be
228
    *                 auto initialised to NULL.
249
    *                 auto initialised to NULL.
229
    */
250
    */
230
    function &getStaticProperty($class, $var)
251
    public static function &getStaticProperty($class, $var)
231
    {
252
    {
232
        static $properties;
253
        static $properties;
233
        if (!isset($properties[$class])) {
254
        if (!isset($properties[$class])) {
-
 
255
            $properties[$class] = array();
234
            $properties[$class] = array();
256
        }
235
        }
257
 
236
        if (!array_key_exists($var, $properties[$class])) {
258
        if (!array_key_exists($var, $properties[$class])) {
-
 
259
            $properties[$class][$var] = null;
237
            $properties[$class][$var] = null;
260
        }
238
        }
261
 
Line 239... Line -...
239
        return $properties[$class][$var];
-
 
240
    }
-
 
241
 
-
 
242
    // }}}
262
        return $properties[$class][$var];
243
    // {{{ registerShutdownFunc()
263
    }
244
 
264
 
245
    /**
265
    /**
246
    * Use this function to register a shutdown method for static
-
 
247
    * classes.
266
    * Use this function to register a shutdown method for static
248
    *
267
    * classes.
-
 
268
    *
249
    * @access public
269
    * @param  mixed $func  The function name (or array of class/method) to call
250
    * @param  mixed $func  The function name (or array of class/method) to call
270
    * @param  mixed $args  The arguments to pass to the function
251
    * @param  mixed $args  The arguments to pass to the function
271
    *
252
    * @return void
272
    * @return void
253
    */
273
    */
254
    function registerShutdownFunc($func, $args = array())
274
    public static function registerShutdownFunc($func, $args = array())
255
    {
275
    {
256
        // if we are called statically, there is a potential
276
        // if we are called statically, there is a potential
257
        // that no shutdown func is registered.  Bug #6445
277
        // that no shutdown func is registered.  Bug #6445
258
        if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
278
        if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
259
            register_shutdown_function("_PEAR_call_destructors");
279
            register_shutdown_function("_PEAR_call_destructors");
260
            $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
280
            $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
Line 261... Line -...
261
        }
-
 
262
        $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
-
 
263
    }
-
 
264
 
281
        }
265
    // }}}
282
        $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
266
    // {{{ isError()
283
    }
267
 
284
 
268
    /**
285
    /**
269
     * Tell whether a value is a PEAR error.
286
     * Tell whether a value is a PEAR error.
270
     *
287
     *
271
     * @param   mixed $data   the value to test
288
     * @param   mixed $data   the value to test
272
     * @param   int   $code   if $data is an error object, return true
289
     * @param   int   $code   if $data is an error object, return true
273
     *                        only if $code is a string and
290
     *                        only if $code is a string and
274
     *                        $obj->getMessage() == $code or
291
     *                        $obj->getMessage() == $code or
275
     *                        $code is an integer and $obj->getCode() == $code
292
     *                        $code is an integer and $obj->getCode() == $code
276
     * @access  public
293
     *
277
     * @return  bool    true if parameter is an error
294
     * @return  bool    true if parameter is an error
-
 
295
     */
-
 
296
    public static function isError($data, $code = null)
-
 
297
    {
278
     */
298
        if (!is_a($data, 'PEAR_Error')) {
279
    function isError($data, $code = null)
299
            return false;
280
    {
300
        }
281
        if (is_a($data, 'PEAR_Error')) {
301
 
282
            if (is_null($code)) {
-
 
283
                return true;
-
 
284
            } elseif (is_string($code)) {
-
 
285
                return $data->getMessage() == $code;
302
        if (is_null($code)) {
286
            } else {
-
 
287
                return $data->getCode() == $code;
-
 
Line -... Line 303...
-
 
303
            return true;
288
            }
304
        } elseif (is_string($code)) {
289
        }
-
 
Line 290... Line 305...
290
        return false;
305
            return $data->getMessage() == $code;
291
    }
306
        }
292
 
307
 
293
    // }}}
308
        return $data->getCode() == $code;
294
    // {{{ setErrorHandling()
309
    }
295
 
310
 
296
    /**
311
    /**
-
 
312
     * Sets how errors generated by this object should be handled.
-
 
313
     * Can be invoked both in objects and statically.  If called
-
 
314
     * statically, setErrorHandling sets the default behaviour for all
297
     * Sets how errors generated by this object should be handled.
315
     * PEAR objects.  If called in an object, setErrorHandling sets
298
     * Can be invoked both in objects and statically.  If called
316
     * the default behaviour for that object.
299
     * statically, setErrorHandling sets the default behaviour for all
317
     *
300
     * PEAR objects.  If called in an object, setErrorHandling sets
318
     * @param object $object
301
     * the default behaviour for that object.
319
     *        Object the method was called on (non-static mode)
Line 329... Line 347...
329
     * @see PEAR_ERROR_CALLBACK
347
     * @see PEAR_ERROR_CALLBACK
330
     * @see PEAR_ERROR_EXCEPTION
348
     * @see PEAR_ERROR_EXCEPTION
331
     *
349
     *
332
     * @since PHP 4.0.5
350
     * @since PHP 4.0.5
333
     */
351
     */
334
 
-
 
-
 
352
    protected static function _setErrorHandling(
335
    function setErrorHandling($mode = null, $options = null)
353
        $object, $mode = null, $options = null
336
    {
354
    ) {
337
        if (isset($this) && is_a($this, 'PEAR')) {
355
        if ($object !== null) {
338
            $setmode     = &$this->_default_error_mode;
356
            $setmode     = &$object->_default_error_mode;
339
            $setoptions  = &$this->_default_error_options;
357
            $setoptions  = &$object->_default_error_options;
340
        } else {
358
        } else {
341
            $setmode     = &$GLOBALS['_PEAR_default_error_mode'];
359
            $setmode     = &$GLOBALS['_PEAR_default_error_mode'];
342
            $setoptions  = &$GLOBALS['_PEAR_default_error_options'];
360
            $setoptions  = &$GLOBALS['_PEAR_default_error_options'];
343
        }
361
        }
Line 367... Line 385...
367
                trigger_error("invalid error mode", E_USER_WARNING);
385
                trigger_error("invalid error mode", E_USER_WARNING);
368
                break;
386
                break;
369
        }
387
        }
370
    }
388
    }
Line 371... Line -...
371
 
-
 
372
    // }}}
-
 
373
    // {{{ expectError()
-
 
374
 
389
 
375
    /**
390
    /**
376
     * This method is used to tell which errors you expect to get.
391
     * This method is used to tell which errors you expect to get.
377
     * Expected errors are always returned with error mode
392
     * Expected errors are always returned with error mode
378
     * PEAR_ERROR_RETURN.  Expected error codes are stored in a stack,
393
     * PEAR_ERROR_RETURN.  Expected error codes are stored in a stack,
Line 392... Line 407...
392
        if (is_array($code)) {
407
        if (is_array($code)) {
393
            array_push($this->_expected_errors, $code);
408
            array_push($this->_expected_errors, $code);
394
        } else {
409
        } else {
395
            array_push($this->_expected_errors, array($code));
410
            array_push($this->_expected_errors, array($code));
396
        }
411
        }
397
        return sizeof($this->_expected_errors);
412
        return count($this->_expected_errors);
398
    }
413
    }
Line 399... Line -...
399
 
-
 
400
    // }}}
-
 
401
    // {{{ popExpect()
-
 
402
 
414
 
403
    /**
415
    /**
404
     * This method pops one element off the expected error codes
416
     * This method pops one element off the expected error codes
405
     * stack.
417
     * stack.
406
     *
418
     *
Line 409... Line 421...
409
    function popExpect()
421
    function popExpect()
410
    {
422
    {
411
        return array_pop($this->_expected_errors);
423
        return array_pop($this->_expected_errors);
412
    }
424
    }
Line 413... Line -...
413
 
-
 
414
    // }}}
-
 
415
    // {{{ _checkDelExpect()
-
 
416
 
425
 
417
    /**
426
    /**
418
     * This method checks unsets an error code if available
427
     * This method checks unsets an error code if available
419
     *
428
     *
420
     * @param mixed error code
429
     * @param mixed error code
Line 423... Line 432...
423
     * @since PHP 4.3.0
432
     * @since PHP 4.3.0
424
     */
433
     */
425
    function _checkDelExpect($error_code)
434
    function _checkDelExpect($error_code)
426
    {
435
    {
427
        $deleted = false;
436
        $deleted = false;
428
 
-
 
429
        foreach ($this->_expected_errors AS $key => $error_array) {
437
        foreach ($this->_expected_errors as $key => $error_array) {
430
            if (in_array($error_code, $error_array)) {
438
            if (in_array($error_code, $error_array)) {
431
                unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
439
                unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
432
                $deleted = true;
440
                $deleted = true;
433
            }
441
            }
Line 434... Line 442...
434
 
442
 
435
            // clean up empty arrays
443
            // clean up empty arrays
436
            if (0 == count($this->_expected_errors[$key])) {
444
            if (0 == count($this->_expected_errors[$key])) {
437
                unset($this->_expected_errors[$key]);
445
                unset($this->_expected_errors[$key]);
438
            }
446
            }
-
 
447
        }
439
        }
448
 
440
        return $deleted;
449
        return $deleted;
Line 441... Line -...
441
    }
-
 
442
 
-
 
443
    // }}}
-
 
444
    // {{{ delExpect()
450
    }
445
 
451
 
446
    /**
452
    /**
447
     * This method deletes all occurences of the specified element from
453
     * This method deletes all occurences of the specified element from
448
     * the expected error codes stack.
454
     * the expected error codes stack.
Line 453... Line 459...
453
     * @since PHP 4.3.0
459
     * @since PHP 4.3.0
454
     */
460
     */
455
    function delExpect($error_code)
461
    function delExpect($error_code)
456
    {
462
    {
457
        $deleted = false;
463
        $deleted = false;
458
 
-
 
459
        if ((is_array($error_code) && (0 != count($error_code)))) {
464
        if ((is_array($error_code) && (0 != count($error_code)))) {
460
            // $error_code is a non-empty array here;
465
            // $error_code is a non-empty array here; we walk through it trying
461
            // we walk through it trying to unset all
-
 
462
            // values
466
            // to unset all values
463
            foreach($error_code as $key => $error) {
467
            foreach ($error_code as $key => $error) {
464
                if ($this->_checkDelExpect($error)) {
468
                $deleted =  $this->_checkDelExpect($error) ? true : false;
465
                    $deleted =  true;
-
 
466
                } else {
-
 
467
                    $deleted = false;
-
 
468
                }
-
 
469
            }
469
            }
-
 
470
 
470
            return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
471
            return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
471
        } elseif (!empty($error_code)) {
472
        } elseif (!empty($error_code)) {
472
            // $error_code comes alone, trying to unset it
473
            // $error_code comes alone, trying to unset it
473
            if ($this->_checkDelExpect($error_code)) {
474
            if ($this->_checkDelExpect($error_code)) {
474
                return true;
475
                return true;
475
            } else {
-
 
476
                return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
-
 
477
            }
476
            }
478
        } else {
-
 
479
            // $error_code is empty
-
 
-
 
477
 
480
            return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
478
            return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
481
        }
479
        }
482
    }
-
 
Line -... Line 480...
-
 
480
 
-
 
481
        // $error_code is empty
483
 
482
        return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
484
    // }}}
-
 
Line 485... Line 483...
485
    // {{{ raiseError()
483
    }
486
 
484
 
487
    /**
485
    /**
488
     * This method is a wrapper that returns an instance of the
486
     * This method is a wrapper that returns an instance of the
Line 514... Line 512...
514
     *                  instantiated from this class, if specified.
512
     *                  instantiated from this class, if specified.
515
     *
513
     *
516
     * @param bool $skipmsg If true, raiseError will only pass error codes,
514
     * @param bool $skipmsg If true, raiseError will only pass error codes,
517
     *                  the error message parameter will be dropped.
515
     *                  the error message parameter will be dropped.
518
     *
516
     *
519
     * @access public
-
 
520
     * @return object   a PEAR error object
517
     * @return object   a PEAR error object
521
     * @see PEAR::setErrorHandling
518
     * @see PEAR::setErrorHandling
522
     * @since PHP 4.0.5
519
     * @since PHP 4.0.5
523
     */
520
     */
-
 
521
    protected static function _raiseError($object,
524
    function &raiseError($message = null,
522
                         $message = null,
525
                         $code = null,
523
                         $code = null,
526
                         $mode = null,
524
                         $mode = null,
527
                         $options = null,
525
                         $options = null,
528
                         $userinfo = null,
526
                         $userinfo = null,
529
                         $error_class = null,
527
                         $error_class = null,
Line 536... Line 534...
536
            $error_class = $message->getType();
534
            $error_class = $message->getType();
537
            $message->error_message_prefix = '';
535
            $message->error_message_prefix = '';
538
            $message     = $message->getMessage();
536
            $message     = $message->getMessage();
539
        }
537
        }
Line -... Line 538...
-
 
538
 
-
 
539
        if (
-
 
540
            $object !== null &&
-
 
541
            isset($object->_expected_errors) &&
540
 
542
            count($object->_expected_errors) > 0 &&
-
 
543
            count($exp = end($object->_expected_errors))
541
        if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && sizeof($exp = end($this->_expected_errors))) {
544
        ) {
542
            if ($exp[0] == "*" ||
545
            if ($exp[0] == "*" ||
543
                (is_int(reset($exp)) && in_array($code, $exp)) ||
546
                (is_int(reset($exp)) && in_array($code, $exp)) ||
-
 
547
                (is_string(reset($exp)) && in_array($message, $exp))
544
                (is_string(reset($exp)) && in_array($message, $exp))) {
548
            ) {
545
                $mode = PEAR_ERROR_RETURN;
549
                $mode = PEAR_ERROR_RETURN;
546
            }
550
            }
-
 
551
        }
547
        }
552
 
548
        // No mode given, try global ones
553
        // No mode given, try global ones
549
        if ($mode === null) {
554
        if ($mode === null) {
550
            // Class error handler
555
            // Class error handler
551
            if (isset($this) && isset($this->_default_error_mode)) {
556
            if ($object !== null && isset($object->_default_error_mode)) {
552
                $mode    = $this->_default_error_mode;
557
                $mode    = $object->_default_error_mode;
553
                $options = $this->_default_error_options;
558
                $options = $object->_default_error_options;
554
            // Global error handler
559
            // Global error handler
555
            } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
560
            } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
556
                $mode    = $GLOBALS['_PEAR_default_error_mode'];
561
                $mode    = $GLOBALS['_PEAR_default_error_mode'];
557
                $options = $GLOBALS['_PEAR_default_error_options'];
562
                $options = $GLOBALS['_PEAR_default_error_options'];
558
            }
563
            }
Line 559... Line 564...
559
        }
564
        }
560
 
565
 
561
        if ($error_class !== null) {
566
        if ($error_class !== null) {
562
            $ec = $error_class;
567
            $ec = $error_class;
563
        } elseif (isset($this) && isset($this->_error_class)) {
568
        } elseif ($object !== null && isset($object->_error_class)) {
564
            $ec = $this->_error_class;
569
            $ec = $object->_error_class;
565
        } else {
570
        } else {
-
 
571
            $ec = 'PEAR_Error';
566
            $ec = 'PEAR_Error';
572
        }
567
        }
573
 
568
        if ($skipmsg) {
-
 
569
            $a = &new $ec($code, $mode, $options, $userinfo);
574
        if ($skipmsg) {
570
            return $a;
575
            $a = new $ec($code, $mode, $options, $userinfo);
571
        } else {
-
 
572
            $a = &new $ec($message, $code, $mode, $options, $userinfo);
576
        } else {
573
            return $a;
-
 
Line 574... Line 577...
574
        }
577
            $a = new $ec($message, $code, $mode, $options, $userinfo);
575
    }
578
        }
Line 576... Line 579...
576
 
579
 
577
    // }}}
580
        return $a;
578
    // {{{ throwError()
581
    }
579
 
582
 
580
    /**
583
    /**
-
 
584
     * Simpler form of raiseError with fewer options.  In most cases
-
 
585
     * message, code and userinfo are enough.
-
 
586
     *
581
     * Simpler form of raiseError with fewer options.  In most cases
587
     * @param mixed $message a text error message or a PEAR error object
-
 
588
     *
-
 
589
     * @param int $code      a numeric error code (it is up to your class
-
 
590
     *                  to define these if you want to use codes)
-
 
591
     *
-
 
592
     * @param string $userinfo If you need to pass along for example debug
582
     * message, code and userinfo are enough.
593
     *                  information, this parameter is meant for that.
583
     *
594
     *
584
     * @param string $message
-
 
585
     *
-
 
586
     */
595
     * @return object   a PEAR error object
587
    function &throwError($message = null,
-
 
588
                         $code = null,
-
 
589
                         $userinfo = null)
596
     * @see PEAR::raiseError
590
    {
-
 
591
        if (isset($this) && is_a($this, 'PEAR')) {
597
     */
592
            $a = &$this->raiseError($message, $code, null, null, $userinfo);
598
    protected static function _throwError($object, $message = null, $code = null, $userinfo = null)
593
            return $a;
599
    {
-
 
600
        if ($object !== null) {
-
 
601
            $a = &$object->raiseError($message, $code, null, null, $userinfo);
-
 
602
            return $a;
594
        } else {
603
        }
Line 595... Line -...
595
            $a = &PEAR::raiseError($message, $code, null, null, $userinfo);
-
 
596
            return $a;
604
 
597
        }
605
        $a = &PEAR::raiseError($message, $code, null, null, $userinfo);
598
    }
606
        return $a;
599
 
607
    }
600
    // }}}
608
 
601
    function staticPushErrorHandling($mode, $options = null)
609
    public static function staticPushErrorHandling($mode, $options = null)
602
    {
610
    {
603
        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
611
        $stack       = &$GLOBALS['_PEAR_error_handler_stack'];
Line 631... Line 639...
631
        }
639
        }
632
        $stack[] = array($mode, $options);
640
        $stack[] = array($mode, $options);
633
        return true;
641
        return true;
634
    }
642
    }
Line 635... Line 643...
635
 
643
 
636
    function staticPopErrorHandling()
644
    public static function staticPopErrorHandling()
637
    {
645
    {
638
        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
646
        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
639
        $setmode     = &$GLOBALS['_PEAR_default_error_mode'];
647
        $setmode     = &$GLOBALS['_PEAR_default_error_mode'];
640
        $setoptions  = &$GLOBALS['_PEAR_default_error_options'];
648
        $setoptions  = &$GLOBALS['_PEAR_default_error_options'];
Line 667... Line 675...
667
                break;
675
                break;
668
        }
676
        }
669
        return true;
677
        return true;
670
    }
678
    }
Line 671... Line -...
671
 
-
 
672
    // {{{ pushErrorHandling()
-
 
673
 
679
 
674
    /**
680
    /**
675
     * Push a new error handler on top of the error handler options stack. With this
681
     * Push a new error handler on top of the error handler options stack. With this
676
     * you can easily override the actual error handler for some code and restore
682
     * you can easily override the actual error handler for some code and restore
677
     * it later with popErrorHandling.
683
     * it later with popErrorHandling.
Line 681... Line 687...
681
     *
687
     *
682
     * @return bool Always true
688
     * @return bool Always true
683
     *
689
     *
684
     * @see PEAR::setErrorHandling
690
     * @see PEAR::setErrorHandling
685
     */
691
     */
686
    function pushErrorHandling($mode, $options = null)
692
    protected static function _pushErrorHandling($object, $mode, $options = null)
687
    {
693
    {
688
        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
694
        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
689
        if (isset($this) && is_a($this, 'PEAR')) {
695
        if ($object !== null) {
690
            $def_mode    = &$this->_default_error_mode;
696
            $def_mode    = &$object->_default_error_mode;
691
            $def_options = &$this->_default_error_options;
697
            $def_options = &$object->_default_error_options;
692
        } else {
698
        } else {
693
            $def_mode    = &$GLOBALS['_PEAR_default_error_mode'];
699
            $def_mode    = &$GLOBALS['_PEAR_default_error_mode'];
694
            $def_options = &$GLOBALS['_PEAR_default_error_options'];
700
            $def_options = &$GLOBALS['_PEAR_default_error_options'];
695
        }
701
        }
696
        $stack[] = array($def_mode, $def_options);
702
        $stack[] = array($def_mode, $def_options);
Line 697... Line 703...
697
 
703
 
698
        if (isset($this) && is_a($this, 'PEAR')) {
704
        if ($object !== null) {
699
            $this->setErrorHandling($mode, $options);
705
            $object->setErrorHandling($mode, $options);
700
        } else {
706
        } else {
701
            PEAR::setErrorHandling($mode, $options);
707
            PEAR::setErrorHandling($mode, $options);
702
        }
708
        }
703
        $stack[] = array($mode, $options);
709
        $stack[] = array($mode, $options);
704
        return true;
710
        return true;
Line 705... Line -...
705
    }
-
 
706
 
-
 
707
    // }}}
-
 
708
    // {{{ popErrorHandling()
711
    }
709
 
712
 
710
    /**
713
    /**
711
    * Pop the last error handler used
714
    * Pop the last error handler used
712
    *
715
    *
713
    * @return bool Always true
716
    * @return bool Always true
714
    *
717
    *
715
    * @see PEAR::pushErrorHandling
718
    * @see PEAR::pushErrorHandling
716
    */
719
    */
717
    function popErrorHandling()
720
    protected static function _popErrorHandling($object)
718
    {
721
    {
719
        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
722
        $stack = &$GLOBALS['_PEAR_error_handler_stack'];
720
        array_pop($stack);
723
        array_pop($stack);
721
        list($mode, $options) = $stack[sizeof($stack) - 1];
724
        list($mode, $options) = $stack[sizeof($stack) - 1];
722
        array_pop($stack);
725
        array_pop($stack);
723
        if (isset($this) && is_a($this, 'PEAR')) {
726
        if ($object !== null) {
724
            $this->setErrorHandling($mode, $options);
727
            $object->setErrorHandling($mode, $options);
725
        } else {
728
        } else {
726
            PEAR::setErrorHandling($mode, $options);
729
            PEAR::setErrorHandling($mode, $options);
727
        }
730
        }
Line 728... Line -...
728
        return true;
-
 
729
    }
-
 
730
 
-
 
731
    // }}}
731
        return true;
732
    // {{{ loadExtension()
732
    }
733
 
733
 
734
    /**
734
    /**
735
    * OS independant PHP extension load. Remember to take care
735
    * OS independent PHP extension load. Remember to take care
736
    * on the correct extension name for case sensitive OSes.
736
    * on the correct extension name for case sensitive OSes.
737
    *
737
    *
738
    * @param string $ext The extension name
738
    * @param string $ext The extension name
739
    * @return bool Success or not on the dl() call
739
    * @return bool Success or not on the dl() call
740
    */
740
    */
741
    function loadExtension($ext)
-
 
742
    {
-
 
743
        if (!extension_loaded($ext)) {
741
    public static function loadExtension($ext)
744
            // if either returns true dl() will produce a FATAL error, stop that
-
 
745
            if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) {
-
 
746
                return false;
-
 
747
            }
-
 
748
            if (OS_WINDOWS) {
-
 
749
                $suffix = '.dll';
-
 
750
            } elseif (PHP_OS == 'HP-UX') {
-
 
751
                $suffix = '.sl';
-
 
752
            } elseif (PHP_OS == 'AIX') {
-
 
753
                $suffix = '.a';
-
 
754
            } elseif (PHP_OS == 'OSX') {
-
 
755
                $suffix = '.bundle';
-
 
756
            } else {
-
 
757
                $suffix = '.so';
742
    {
758
            }
-
 
759
            return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
-
 
Line -... Line 743...
-
 
743
        if (extension_loaded($ext)) {
-
 
744
            return true;
-
 
745
        }
-
 
746
 
-
 
747
        // if either returns true dl() will produce a FATAL error, stop that
-
 
748
        if (
760
        }
749
            function_exists('dl') === false ||
761
        return true;
750
            ini_get('enable_dl') != 1
-
 
751
        ) {
-
 
752
            return false;
-
 
753
        }
-
 
754
 
-
 
755
        if (OS_WINDOWS) {
-
 
756
            $suffix = '.dll';
-
 
757
        } elseif (PHP_OS == 'HP-UX') {
-
 
758
            $suffix = '.sl';
-
 
759
        } elseif (PHP_OS == 'AIX') {
-
 
760
            $suffix = '.a';
-
 
761
        } elseif (PHP_OS == 'OSX') {
Line 762... Line 762...
762
    }
762
            $suffix = '.bundle';
-
 
763
        } else {
-
 
764
            $suffix = '.so';
Line 763... Line 765...
763
 
765
        }
764
    // }}}
766
 
765
}
767
        return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
766
 
768
    }
767
// {{{ _PEAR_call_destructors()
769
}
768
 
770
 
769
function _PEAR_call_destructors()
771
function _PEAR_call_destructors()
-
 
772
{
770
{
773
    global $_PEAR_destructor_object_list;
-
 
774
    if (is_array($_PEAR_destructor_object_list) &&
-
 
775
        sizeof($_PEAR_destructor_object_list))
771
    global $_PEAR_destructor_object_list;
776
    {
772
    if (is_array($_PEAR_destructor_object_list) &&
777
        reset($_PEAR_destructor_object_list);
-
 
778
 
773
        sizeof($_PEAR_destructor_object_list))
779
        $destructLifoExists = PEAR::getStaticProperty('PEAR', 'destructlifo');
774
    {
780
 
775
        reset($_PEAR_destructor_object_list);
781
        if ($destructLifoExists) {
776
        if (PEAR::getStaticProperty('PEAR', 'destructlifo')) {
782
            $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
777
            $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
783
        }
Line 792... Line 798...
792
        // not called more than once.
798
        // not called more than once.
793
        $_PEAR_destructor_object_list = array();
799
        $_PEAR_destructor_object_list = array();
794
    }
800
    }
Line 795... Line 801...
795
 
801
 
-
 
802
    // Now call the shutdown functions
-
 
803
    if (
796
    // Now call the shutdown functions
804
        isset($GLOBALS['_PEAR_shutdown_funcs']) &&
-
 
805
        is_array($GLOBALS['_PEAR_shutdown_funcs']) &&
-
 
806
        !empty($GLOBALS['_PEAR_shutdown_funcs'])
797
    if (is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) {
807
    ) {
798
        foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
808
        foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
799
            call_user_func_array($value[0], $value[1]);
809
            call_user_func_array($value[0], $value[1]);
800
        }
810
        }
801
    }
811
    }
Line 802... Line -...
802
}
-
 
803
 
812
}
804
// }}}
813
 
805
/**
814
/**
806
 * Standard PEAR error class for PHP 4
815
 * Standard PEAR error class for PHP 4
807
 *
816
 *
Line 811... Line 820...
811
 * @package    PEAR
820
 * @package    PEAR
812
 * @author     Stig Bakken <ssb@php.net>
821
 * @author     Stig Bakken <ssb@php.net>
813
 * @author     Tomas V.V. Cox <cox@idecnet.com>
822
 * @author     Tomas V.V. Cox <cox@idecnet.com>
814
 * @author     Gregory Beaver <cellog@php.net>
823
 * @author     Gregory Beaver <cellog@php.net>
815
 * @copyright  1997-2006 The PHP Group
824
 * @copyright  1997-2006 The PHP Group
816
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
825
 * @license    http://opensource.org/licenses/bsd-license.php New BSD License
817
 * @version    Release: 1.5.1
826
 * @version    Release: 1.10.1
818
 * @link       http://pear.php.net/manual/en/core.pear.pear-error.php
827
 * @link       http://pear.php.net/manual/en/core.pear.pear-error.php
819
 * @see        PEAR::raiseError(), PEAR::throwError()
828
 * @see        PEAR::raiseError(), PEAR::throwError()
820
 * @since      Class available since PHP 4.0.2
829
 * @since      Class available since PHP 4.0.2
821
 */
830
 */
822
class PEAR_Error
831
class PEAR_Error
823
{
832
{
824
    // {{{ properties
-
 
825
 
-
 
826
    var $error_message_prefix = '';
833
    var $error_message_prefix = '';
827
    var $mode                 = PEAR_ERROR_RETURN;
834
    var $mode                 = PEAR_ERROR_RETURN;
828
    var $level                = E_USER_NOTICE;
835
    var $level                = E_USER_NOTICE;
829
    var $code                 = -1;
836
    var $code                 = -1;
830
    var $message              = '';
837
    var $message              = '';
831
    var $userinfo             = '';
838
    var $userinfo             = '';
832
    var $backtrace            = null;
839
    var $backtrace            = null;
Line 833... Line -...
833
 
-
 
834
    // }}}
-
 
835
    // {{{ constructor
-
 
836
 
840
 
837
    /**
841
    /**
838
     * PEAR_Error constructor
842
     * PEAR_Error constructor
839
     *
843
     *
840
     * @param string $message  message
844
     * @param string $message  message
Line 852... Line 856...
852
     * @param string $userinfo (optional) additional user/debug info
856
     * @param string $userinfo (optional) additional user/debug info
853
     *
857
     *
854
     * @access public
858
     * @access public
855
     *
859
     *
856
     */
860
     */
857
    function PEAR_Error($message = 'unknown error', $code = null,
861
    function __construct($message = 'unknown error', $code = null,
858
                        $mode = null, $options = null, $userinfo = null)
862
                        $mode = null, $options = null, $userinfo = null)
859
    {
863
    {
860
        if ($mode === null) {
864
        if ($mode === null) {
861
            $mode = PEAR_ERROR_RETURN;
865
            $mode = PEAR_ERROR_RETURN;
862
        }
866
        }
863
        $this->message   = $message;
867
        $this->message   = $message;
864
        $this->code      = $code;
868
        $this->code      = $code;
865
        $this->mode      = $mode;
869
        $this->mode      = $mode;
866
        $this->userinfo  = $userinfo;
870
        $this->userinfo  = $userinfo;
-
 
871
 
867
        if (!PEAR::getStaticProperty('PEAR_Error', 'skiptrace')) {
872
        $skiptrace = PEAR::getStaticProperty('PEAR_Error', 'skiptrace');
-
 
873
 
-
 
874
        if (!$skiptrace) {
868
            $this->backtrace = debug_backtrace();
875
            $this->backtrace = debug_backtrace();
869
            if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) {
876
            if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) {
870
                unset($this->backtrace[0]['object']);
877
                unset($this->backtrace[0]['object']);
871
            }
878
            }
872
        }
879
        }
-
 
880
 
873
        if ($mode & PEAR_ERROR_CALLBACK) {
881
        if ($mode & PEAR_ERROR_CALLBACK) {
874
            $this->level = E_USER_NOTICE;
882
            $this->level = E_USER_NOTICE;
875
            $this->callback = $options;
883
            $this->callback = $options;
876
        } else {
884
        } else {
877
            if ($options === null) {
885
            if ($options === null) {
878
                $options = E_USER_NOTICE;
886
                $options = E_USER_NOTICE;
879
            }
887
            }
-
 
888
 
880
            $this->level = $options;
889
            $this->level = $options;
881
            $this->callback = null;
890
            $this->callback = null;
882
        }
891
        }
-
 
892
 
883
        if ($this->mode & PEAR_ERROR_PRINT) {
893
        if ($this->mode & PEAR_ERROR_PRINT) {
884
            if (is_null($options) || is_int($options)) {
894
            if (is_null($options) || is_int($options)) {
885
                $format = "%s";
895
                $format = "%s";
886
            } else {
896
            } else {
887
                $format = $options;
897
                $format = $options;
888
            }
898
            }
-
 
899
 
889
            printf($format, $this->getMessage());
900
            printf($format, $this->getMessage());
890
        }
901
        }
-
 
902
 
891
        if ($this->mode & PEAR_ERROR_TRIGGER) {
903
        if ($this->mode & PEAR_ERROR_TRIGGER) {
892
            trigger_error($this->getMessage(), $this->level);
904
            trigger_error($this->getMessage(), $this->level);
893
        }
905
        }
-
 
906
 
894
        if ($this->mode & PEAR_ERROR_DIE) {
907
        if ($this->mode & PEAR_ERROR_DIE) {
895
            $msg = $this->getMessage();
908
            $msg = $this->getMessage();
896
            if (is_null($options) || is_int($options)) {
909
            if (is_null($options) || is_int($options)) {
897
                $format = "%s";
910
                $format = "%s";
898
                if (substr($msg, -1) != "\n") {
911
                if (substr($msg, -1) != "\n") {
Line 901... Line 914...
901
            } else {
914
            } else {
902
                $format = $options;
915
                $format = $options;
903
            }
916
            }
904
            die(sprintf($format, $msg));
917
            die(sprintf($format, $msg));
905
        }
918
        }
-
 
919
 
906
        if ($this->mode & PEAR_ERROR_CALLBACK) {
920
        if ($this->mode & PEAR_ERROR_CALLBACK && is_callable($this->callback)) {
907
            if (is_callable($this->callback)) {
-
 
908
                call_user_func($this->callback, $this);
921
            call_user_func($this->callback, $this);
909
            }
-
 
910
        }
922
        }
-
 
923
 
911
        if ($this->mode & PEAR_ERROR_EXCEPTION) {
924
        if ($this->mode & PEAR_ERROR_EXCEPTION) {
912
            trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
925
            trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
913
            eval('$e = new Exception($this->message, $this->code);throw($e);');
926
            eval('$e = new Exception($this->message, $this->code);throw($e);');
914
        }
927
        }
915
    }
928
    }
Line 916... Line 929...
916
 
929
 
-
 
930
    /**
-
 
931
     * Only here for backwards compatibility.
-
 
932
     *
-
 
933
     * Class "Cache_Error" still uses it, among others.
-
 
934
     *
-
 
935
     * @param string $message  Message
-
 
936
     * @param int    $code     Error code
-
 
937
     * @param int    $mode     Error mode
-
 
938
     * @param mixed  $options  See __construct()
-
 
939
     * @param string $userinfo Additional user/debug info
917
    // }}}
940
     */
-
 
941
    public function PEAR_Error(
-
 
942
        $message = 'unknown error', $code = null, $mode = null,
-
 
943
        $options = null, $userinfo = null
-
 
944
    ) {
-
 
945
        self::__construct($message, $code, $mode, $options, $userinfo);
Line 918... Line 946...
918
    // {{{ getMode()
946
    }
919
 
947
 
920
    /**
948
    /**
921
     * Get the error mode from an error object.
949
     * Get the error mode from an error object.
922
     *
950
     *
923
     * @return int error mode
951
     * @return int error mode
924
     * @access public
952
     * @access public
-
 
953
     */
925
     */
954
    function getMode()
926
    function getMode() {
955
    {
Line 927... Line -...
927
        return $this->mode;
-
 
928
    }
-
 
929
 
-
 
930
    // }}}
956
        return $this->mode;
931
    // {{{ getCallback()
957
    }
932
 
958
 
933
    /**
959
    /**
934
     * Get the callback function/method from an error object.
960
     * Get the callback function/method from an error object.
935
     *
961
     *
936
     * @return mixed callback function or object/method array
962
     * @return mixed callback function or object/method array
-
 
963
     * @access public
937
     * @access public
964
     */
938
     */
965
    function getCallback()
Line 939... Line -...
939
    function getCallback() {
-
 
940
        return $this->callback;
-
 
941
    }
-
 
942
 
-
 
943
    // }}}
966
    {
944
    // {{{ getMessage()
967
        return $this->callback;
945
 
968
    }
946
 
969
 
947
    /**
970
    /**
Line 953... Line 976...
953
    function getMessage()
976
    function getMessage()
954
    {
977
    {
955
        return ($this->error_message_prefix . $this->message);
978
        return ($this->error_message_prefix . $this->message);
956
    }
979
    }
Line 957... Line -...
957
 
-
 
958
 
-
 
959
    // }}}
-
 
960
    // {{{ getCode()
-
 
961
 
980
 
962
    /**
981
    /**
963
     * Get error code from an error object
982
     * Get error code from an error object
964
     *
983
     *
965
     * @return int error code
984
     * @return int error code
Line 968... Line 987...
968
     function getCode()
987
     function getCode()
969
     {
988
     {
970
        return $this->code;
989
        return $this->code;
971
     }
990
     }
Line 972... Line -...
972
 
-
 
973
    // }}}
-
 
974
    // {{{ getType()
-
 
975
 
991
 
976
    /**
992
    /**
977
     * Get the name of this error/exception.
993
     * Get the name of this error/exception.
978
     *
994
     *
979
     * @return string error/exception name (type)
995
     * @return string error/exception name (type)
Line 982... Line 998...
982
    function getType()
998
    function getType()
983
    {
999
    {
984
        return get_class($this);
1000
        return get_class($this);
985
    }
1001
    }
Line 986... Line -...
986
 
-
 
987
    // }}}
-
 
988
    // {{{ getUserInfo()
-
 
989
 
1002
 
990
    /**
1003
    /**
991
     * Get additional user-supplied information.
1004
     * Get additional user-supplied information.
992
     *
1005
     *
993
     * @return string user-supplied information
1006
     * @return string user-supplied information
Line 996... Line 1009...
996
    function getUserInfo()
1009
    function getUserInfo()
997
    {
1010
    {
998
        return $this->userinfo;
1011
        return $this->userinfo;
999
    }
1012
    }
Line 1000... Line -...
1000
 
-
 
1001
    // }}}
-
 
1002
    // {{{ getDebugInfo()
-
 
1003
 
1013
 
1004
    /**
1014
    /**
1005
     * Get additional debug information supplied by the application.
1015
     * Get additional debug information supplied by the application.
1006
     *
1016
     *
1007
     * @return string debug information
1017
     * @return string debug information
Line 1010... Line 1020...
1010
    function getDebugInfo()
1020
    function getDebugInfo()
1011
    {
1021
    {
1012
        return $this->getUserInfo();
1022
        return $this->getUserInfo();
1013
    }
1023
    }
Line 1014... Line -...
1014
 
-
 
1015
    // }}}
-
 
1016
    // {{{ getBacktrace()
-
 
1017
 
1024
 
1018
    /**
1025
    /**
1019
     * Get the call backtrace from where the error was generated.
1026
     * Get the call backtrace from where the error was generated.
1020
     * Supported with PHP 4.3.0 or newer.
1027
     * Supported with PHP 4.3.0 or newer.
1021
     *
1028
     *
Line 1032... Line 1039...
1032
            return $this->backtrace;
1039
            return $this->backtrace;
1033
        }
1040
        }
1034
        return $this->backtrace[$frame];
1041
        return $this->backtrace[$frame];
1035
    }
1042
    }
Line 1036... Line -...
1036
 
-
 
1037
    // }}}
-
 
1038
    // {{{ addUserInfo()
-
 
1039
 
1043
 
1040
    function addUserInfo($info)
1044
    function addUserInfo($info)
1041
    {
1045
    {
1042
        if (empty($this->userinfo)) {
1046
        if (empty($this->userinfo)) {
1043
            $this->userinfo = $info;
1047
            $this->userinfo = $info;
1044
        } else {
1048
        } else {
1045
            $this->userinfo .= " ** $info";
1049
            $this->userinfo .= " ** $info";
1046
        }
1050
        }
Line -... Line 1051...
-
 
1051
    }
1047
    }
1052
 
1048
 
1053
    function __toString()
-
 
1054
    {
Line 1049... Line 1055...
1049
    // }}}
1055
        return $this->getMessage();
1050
    // {{{ toString()
1056
    }
1051
 
1057
 
1052
    /**
1058
    /**
1053
     * Make a string representation of this object.
1059
     * Make a string representation of this object.
1054
     *
1060
     *
1055
     * @return string a string with an object summary
1061
     * @return string a string with an object summary
-
 
1062
     * @access public
1056
     * @access public
1063
     */
1057
     */
1064
    function toString()
1058
    function toString() {
1065
    {
1059
        $modes = array();
1066
        $modes = array();
1060
        $levels = array(E_USER_NOTICE  => 'notice',
1067
        $levels = array(E_USER_NOTICE  => 'notice',
Line 1092... Line 1099...
1092
                       strtolower(get_class($this)), $this->message, $this->code,
1099
                       strtolower(get_class($this)), $this->message, $this->code,
1093
                       implode("|", $modes), $levels[$this->level],
1100
                       implode("|", $modes), $levels[$this->level],
1094
                       $this->error_message_prefix,
1101
                       $this->error_message_prefix,
1095
                       $this->userinfo);
1102
                       $this->userinfo);
1096
    }
1103
    }
1097
 
-
 
1098
    // }}}
-
 
1099
}
1104
}
Line 1100... Line 1105...
1100
 
1105
 
1101
/*
1106
/*
1102
 * Local Variables:
1107
 * Local Variables:
1103
 * mode: php
1108
 * mode: php
1104
 * tab-width: 4
1109
 * tab-width: 4
1105
 * c-basic-offset: 4
1110
 * c-basic-offset: 4
1106
 * End:
1111
 * End:
1107
 */
-