Subversion Repositories Applications.papyrus

Rev

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

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