annotate vendor/pear/pear-core-minimal/src/PEAR.php @ 4:888e774ee983

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