| version 1.3, 2005/11/25 09:49:46 |
version 1.4, 2011/06/17 13:56:38 |
|
|
| <?php
|
<?php |
| /**
|
/** |
| * PEAR, the PHP Extension and Application Repository
|
* PEAR, the PHP Extension and Application Repository |
| *
|
* |
| * PEAR class and PEAR_Error class
|
* PEAR class and PEAR_Error class |
| *
|
* |
| * PHP versions 4 and 5
|
* PHP versions 4 and 5 |
| *
|
* |
| * LICENSE: This source file is subject to version 3.0 of the PHP license
|
* @category pear |
| * that is available through the world-wide-web at the following URI:
|
* @package PEAR |
| * http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
* @author Sterling Hughes <sterling@php.net> |
| * the PHP License and are unable to obtain it through the web, please
|
* @author Stig Bakken <ssb@php.net> |
| * send a note to license@php.net so we can mail you a copy immediately.
|
* @author Tomas V.V.Cox <cox@idecnet.com> |
| *
|
* @author Greg Beaver <cellog@php.net> |
| * @category pear
|
* @copyright 1997-2010 The Authors |
| * @package PEAR
|
* @license http://opensource.org/licenses/bsd-license.php New BSD License |
| * @author Sterling Hughes <sterling@php.net>
|
* @version CVS: $Id$ |
| * @author Stig Bakken <ssb@php.net>
|
* @link http://pear.php.net/package/PEAR |
| * @author Tomas V.V.Cox <cox@idecnet.com>
|
* @since File available since Release 0.1 |
| * @author Greg Beaver <cellog@php.net>
|
*/ |
| * @copyright 1997-2005 The PHP Group
|
|
| * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
/**#@+ |
| * @version CVS: $Id$
|
* ERROR constants |
| * @link http://pear.php.net/package/PEAR
|
*/ |
| * @since File available since Release 0.1
|
define('PEAR_ERROR_RETURN', 1); |
| */
|
define('PEAR_ERROR_PRINT', 2); |
|
|
define('PEAR_ERROR_TRIGGER', 4); |
| /**#@+
|
define('PEAR_ERROR_DIE', 8); |
| * ERROR constants
|
define('PEAR_ERROR_CALLBACK', 16); |
| */
|
/** |
| define('PEAR_ERROR_RETURN', 1);
|
* WARNING: obsolete |
| define('PEAR_ERROR_PRINT', 2);
|
* @deprecated |
| define('PEAR_ERROR_TRIGGER', 4);
|
*/ |
| define('PEAR_ERROR_DIE', 8);
|
define('PEAR_ERROR_EXCEPTION', 32); |
| define('PEAR_ERROR_CALLBACK', 16);
|
/**#@-*/ |
| /**
|
define('PEAR_ZE2', (function_exists('version_compare') && |
| * WARNING: obsolete
|
version_compare(zend_version(), "2-dev", "ge"))); |
| * @deprecated
|
|
| */
|
if (substr(PHP_OS, 0, 3) == 'WIN') { |
| define('PEAR_ERROR_EXCEPTION', 32);
|
define('OS_WINDOWS', true); |
| /**#@-*/
|
define('OS_UNIX', false); |
| define('PEAR_ZE2', (function_exists('version_compare') &&
|
define('PEAR_OS', 'Windows'); |
| version_compare(zend_version(), "2-dev", "ge")));
|
} else { |
|
|
define('OS_WINDOWS', false); |
| if (substr(PHP_OS, 0, 3) == 'WIN') {
|
define('OS_UNIX', true); |
| define('OS_WINDOWS', true);
|
define('PEAR_OS', 'Unix'); // blatant assumption |
| define('OS_UNIX', false);
|
} |
| define('PEAR_OS', 'Windows');
|
|
| } else {
|
$GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_RETURN; |
| define('OS_WINDOWS', false);
|
$GLOBALS['_PEAR_default_error_options'] = E_USER_NOTICE; |
| define('OS_UNIX', true);
|
$GLOBALS['_PEAR_destructor_object_list'] = array(); |
| define('PEAR_OS', 'Unix'); // blatant assumption
|
$GLOBALS['_PEAR_shutdown_funcs'] = array(); |
| }
|
$GLOBALS['_PEAR_error_handler_stack'] = array(); |
|
|
|
| // instant backwards compatibility
|
@ini_set('track_errors', true); |
| if (!defined('PATH_SEPARATOR')) {
|
|
| if (OS_WINDOWS) {
|
/** |
| define('PATH_SEPARATOR', ';');
|
* Base class for other PEAR classes. Provides rudimentary |
| } else {
|
* emulation of destructors. |
| define('PATH_SEPARATOR', ':');
|
* |
| }
|
* If you want a destructor in your class, inherit PEAR and make a |
| }
|
* destructor method called _yourclassname (same name as the |
|
|
* constructor, but with a "_" prefix). Also, in your constructor you |
| $GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_RETURN;
|
* have to call the PEAR constructor: $this->PEAR();. |
| $GLOBALS['_PEAR_default_error_options'] = E_USER_NOTICE;
|
* The destructor method will be called without parameters. Note that |
| $GLOBALS['_PEAR_destructor_object_list'] = array();
|
* at in some SAPI implementations (such as Apache), any output during |
| $GLOBALS['_PEAR_shutdown_funcs'] = array();
|
* the request shutdown (in which destructors are called) seems to be |
| $GLOBALS['_PEAR_error_handler_stack'] = array();
|
* discarded. If you need to get any debug information from your |
|
|
* destructor, use error_log(), syslog() or something similar. |
| @ini_set('track_errors', true);
|
* |
|
|
* IMPORTANT! To use the emulated destructors you need to create the |
| /**
|
* objects by reference: $obj =& new PEAR_child; |
| * Base class for other PEAR classes. Provides rudimentary
|
* |
| * emulation of destructors.
|
* @category pear |
| *
|
* @package PEAR |
| * If you want a destructor in your class, inherit PEAR and make a
|
* @author Stig Bakken <ssb@php.net> |
| * destructor method called _yourclassname (same name as the
|
* @author Tomas V.V. Cox <cox@idecnet.com> |
| * constructor, but with a "_" prefix). Also, in your constructor you
|
* @author Greg Beaver <cellog@php.net> |
| * have to call the PEAR constructor: $this->PEAR();.
|
* @copyright 1997-2006 The PHP Group |
| * The destructor method will be called without parameters. Note that
|
* @license http://opensource.org/licenses/bsd-license.php New BSD License |
| * at in some SAPI implementations (such as Apache), any output during
|
* @version Release: 1.9.3 |
| * the request shutdown (in which destructors are called) seems to be
|
* @link http://pear.php.net/package/PEAR |
| * discarded. If you need to get any debug information from your
|
* @see PEAR_Error |
| * destructor, use error_log(), syslog() or something similar.
|
* @since Class available since PHP 4.0.2 |
| *
|
* @link http://pear.php.net/manual/en/core.pear.php#core.pear.pear |
| * IMPORTANT! To use the emulated destructors you need to create the
|
*/ |
| * objects by reference: $obj =& new PEAR_child;
|
class PEAR |
| *
|
{ |
| * @category pear
|
/** |
| * @package PEAR
|
* Whether to enable internal debug messages. |
| * @author Stig Bakken <ssb@php.net>
|
* |
| * @author Tomas V.V. Cox <cox@idecnet.com>
|
* @var bool |
| * @author Greg Beaver <cellog@php.net>
|
* @access private |
| * @copyright 1997-2005 The PHP Group
|
*/ |
| * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
var $_debug = false; |
| * @version Release: 1.4.5
|
|
| * @link http://pear.php.net/package/PEAR
|
/** |
| * @see PEAR_Error
|
* Default error mode for this object. |
| * @since Class available since PHP 4.0.2
|
* |
| * @link http://pear.php.net/manual/en/core.pear.php#core.pear.pear
|
* @var int |
| */
|
* @access private |
| class PEAR
|
*/ |
| {
|
var $_default_error_mode = null; |
| // {{{ properties
|
|
|
|
/** |
| /**
|
* Default error options used for this object when error mode |
| * Whether to enable internal debug messages.
|
* is PEAR_ERROR_TRIGGER. |
| *
|
* |
| * @var bool
|
* @var int |
| * @access private
|
* @access private |
| */
|
*/ |
| var $_debug = false;
|
var $_default_error_options = null; |
|
|
|
| /**
|
/** |
| * Default error mode for this object.
|
* Default error handler (callback) for this object, if error mode is |
| *
|
* PEAR_ERROR_CALLBACK. |
| * @var int
|
* |
| * @access private
|
* @var string |
| */
|
* @access private |
| var $_default_error_mode = null;
|
*/ |
|
|
var $_default_error_handler = ''; |
| /**
|
|
| * Default error options used for this object when error mode
|
/** |
| * is PEAR_ERROR_TRIGGER.
|
* Which class to use for error objects. |
| *
|
* |
| * @var int
|
* @var string |
| * @access private
|
* @access private |
| */
|
*/ |
| var $_default_error_options = null;
|
var $_error_class = 'PEAR_Error'; |
|
|
|
| /**
|
/** |
| * Default error handler (callback) for this object, if error mode is
|
* An array of expected errors. |
| * PEAR_ERROR_CALLBACK.
|
* |
| *
|
* @var array |
| * @var string
|
* @access private |
| * @access private
|
*/ |
| */
|
var $_expected_errors = array(); |
| var $_default_error_handler = '';
|
|
|
|
/** |
| /**
|
* Constructor. Registers this object in |
| * Which class to use for error objects.
|
* $_PEAR_destructor_object_list for destructor emulation if a |
| *
|
* destructor object exists. |
| * @var string
|
* |
| * @access private
|
* @param string $error_class (optional) which class to use for |
| */
|
* error objects, defaults to PEAR_Error. |
| var $_error_class = 'PEAR_Error';
|
* @access public |
|
|
* @return void |
| /**
|
*/ |
| * An array of expected errors.
|
function PEAR($error_class = null) |
| *
|
{ |
| * @var array
|
$classname = strtolower(get_class($this)); |
| * @access private
|
if ($this->_debug) { |
| */
|
print "PEAR constructor called, class=$classname\n"; |
| var $_expected_errors = array();
|
} |
|
|
|
| // }}}
|
if ($error_class !== null) { |
|
|
$this->_error_class = $error_class; |
| // {{{ constructor
|
} |
|
|
|
| /**
|
while ($classname && strcasecmp($classname, "pear")) { |
| * Constructor. Registers this object in
|
$destructor = "_$classname"; |
| * $_PEAR_destructor_object_list for destructor emulation if a
|
if (method_exists($this, $destructor)) { |
| * destructor object exists.
|
global $_PEAR_destructor_object_list; |
| *
|
$_PEAR_destructor_object_list[] = &$this; |
| * @param string $error_class (optional) which class to use for
|
if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) { |
| * error objects, defaults to PEAR_Error.
|
register_shutdown_function("_PEAR_call_destructors"); |
| * @access public
|
$GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true; |
| * @return void
|
} |
| */
|
break; |
| function PEAR($error_class = null)
|
} else { |
| {
|
$classname = get_parent_class($classname); |
| $classname = strtolower(get_class($this));
|
} |
| if ($this->_debug) {
|
} |
| print "PEAR constructor called, class=$classname\n";
|
} |
| }
|
|
| if ($error_class !== null) {
|
/** |
| $this->_error_class = $error_class;
|
* Destructor (the emulated type of...). Does nothing right now, |
| }
|
* but is included for forward compatibility, so subclass |
| while ($classname && strcasecmp($classname, "pear")) {
|
* destructors should always call it. |
| $destructor = "_$classname";
|
* |
| if (method_exists($this, $destructor)) {
|
* See the note in the class desciption about output from |
| global $_PEAR_destructor_object_list;
|
* destructors. |
| $_PEAR_destructor_object_list[] = &$this;
|
* |
| if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) {
|
* @access public |
| register_shutdown_function("_PEAR_call_destructors");
|
* @return void |
| $GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true;
|
*/ |
| }
|
function _PEAR() { |
| break;
|
if ($this->_debug) { |
| } else {
|
printf("PEAR destructor called, class=%s\n", strtolower(get_class($this))); |
| $classname = get_parent_class($classname);
|
} |
| }
|
} |
| }
|
|
| }
|
/** |
|
|
* If you have a class that's mostly/entirely static, and you need static |
| // }}}
|
* properties, you can use this method to simulate them. Eg. in your method(s) |
| // {{{ destructor
|
* do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar'); |
|
|
* You MUST use a reference, or they will not persist! |
| /**
|
* |
| * Destructor (the emulated type of...). Does nothing right now,
|
* @access public |
| * but is included for forward compatibility, so subclass
|
* @param string $class The calling classname, to prevent clashes |
| * destructors should always call it.
|
* @param string $var The variable to retrieve. |
| *
|
* @return mixed A reference to the variable. If not set it will be |
| * See the note in the class desciption about output from
|
* auto initialised to NULL. |
| * destructors.
|
*/ |
| *
|
function &getStaticProperty($class, $var) |
| * @access public
|
{ |
| * @return void
|
static $properties; |
| */
|
if (!isset($properties[$class])) { |
| function _PEAR() {
|
$properties[$class] = array(); |
| if ($this->_debug) {
|
} |
| printf("PEAR destructor called, class=%s\n", strtolower(get_class($this)));
|
|
| }
|
if (!array_key_exists($var, $properties[$class])) { |
| }
|
$properties[$class][$var] = null; |
|
|
} |
| // }}}
|
|
| // {{{ getStaticProperty()
|
return $properties[$class][$var]; |
|
|
} |
| /**
|
|
| * If you have a class that's mostly/entirely static, and you need static
|
/** |
| * properties, you can use this method to simulate them. Eg. in your method(s)
|
* Use this function to register a shutdown method for static |
| * do this: $myVar = &PEAR::getStaticProperty('myclass', 'myVar');
|
* classes. |
| * You MUST use a reference, or they will not persist!
|
* |
| *
|
* @access public |
| * @access public
|
* @param mixed $func The function name (or array of class/method) to call |
| * @param string $class The calling classname, to prevent clashes
|
* @param mixed $args The arguments to pass to the function |
| * @param string $var The variable to retrieve.
|
* @return void |
| * @return mixed A reference to the variable. If not set it will be
|
*/ |
| * auto initialised to NULL.
|
function registerShutdownFunc($func, $args = array()) |
| */
|
{ |
| function &getStaticProperty($class, $var)
|
// if we are called statically, there is a potential |
| {
|
// that no shutdown func is registered. Bug #6445 |
| static $properties;
|
if (!isset($GLOBALS['_PEAR_SHUTDOWN_REGISTERED'])) { |
| return $properties[$class][$var];
|
register_shutdown_function("_PEAR_call_destructors"); |
| }
|
$GLOBALS['_PEAR_SHUTDOWN_REGISTERED'] = true; |
|
|
} |
| // }}}
|
$GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args); |
| // {{{ registerShutdownFunc()
|
} |
|
|
|
| /**
|
/** |
| * Use this function to register a shutdown method for static
|
* Tell whether a value is a PEAR error. |
| * classes.
|
* |
| *
|
* @param mixed $data the value to test |
| * @access public
|
* @param int $code if $data is an error object, return true |
| * @param mixed $func The function name (or array of class/method) to call
|
* only if $code is a string and |
| * @param mixed $args The arguments to pass to the function
|
* $obj->getMessage() == $code or |
| * @return void
|
* $code is an integer and $obj->getCode() == $code |
| */
|
* @access public |
| function registerShutdownFunc($func, $args = array())
|
* @return bool true if parameter is an error |
| {
|
*/ |
| $GLOBALS['_PEAR_shutdown_funcs'][] = array($func, $args);
|
function isError($data, $code = null) |
| }
|
{ |
|
|
if (!is_a($data, 'PEAR_Error')) { |
| // }}}
|
return false; |
| // {{{ isError()
|
} |
|
|
|
| /**
|
if (is_null($code)) { |
| * Tell whether a value is a PEAR error.
|
return true; |
| *
|
} elseif (is_string($code)) { |
| * @param mixed $data the value to test
|
return $data->getMessage() == $code; |
| * @param int $code if $data is an error object, return true
|
} |
| * only if $code is a string and
|
|
| * $obj->getMessage() == $code or
|
return $data->getCode() == $code; |
| * $code is an integer and $obj->getCode() == $code
|
} |
| * @access public
|
|
| * @return bool true if parameter is an error
|
/** |
| */
|
* Sets how errors generated by this object should be handled. |
| function isError($data, $code = null)
|
* Can be invoked both in objects and statically. If called |
| {
|
* statically, setErrorHandling sets the default behaviour for all |
| if (is_a($data, 'PEAR_Error')) {
|
* PEAR objects. If called in an object, setErrorHandling sets |
| if (is_null($code)) {
|
* the default behaviour for that object. |
| return true;
|
* |
| } elseif (is_string($code)) {
|
* @param int $mode |
| return $data->getMessage() == $code;
|
* One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT, |
| } else {
|
* PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE, |
| return $data->getCode() == $code;
|
* PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION. |
| }
|
* |
| }
|
* @param mixed $options |
| return false;
|
* When $mode is PEAR_ERROR_TRIGGER, this is the error level (one |
| }
|
* of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR). |
|
|
* |
| // }}}
|
* When $mode is PEAR_ERROR_CALLBACK, this parameter is expected |
| // {{{ setErrorHandling()
|
* to be the callback function or method. A callback |
|
|
* function is a string with the name of the function, a |
| /**
|
* callback method is an array of two elements: the element |
| * Sets how errors generated by this object should be handled.
|
* at index 0 is the object, and the element at index 1 is |
| * Can be invoked both in objects and statically. If called
|
* the name of the method to call in the object. |
| * statically, setErrorHandling sets the default behaviour for all
|
* |
| * PEAR objects. If called in an object, setErrorHandling sets
|
* When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is |
| * the default behaviour for that object.
|
* a printf format string used when printing the error |
| *
|
* message. |
| * @param int $mode
|
* |
| * One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
|
* @access public |
| * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
|
* @return void |
| * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION.
|
* @see PEAR_ERROR_RETURN |
| *
|
* @see PEAR_ERROR_PRINT |
| * @param mixed $options
|
* @see PEAR_ERROR_TRIGGER |
| * When $mode is PEAR_ERROR_TRIGGER, this is the error level (one
|
* @see PEAR_ERROR_DIE |
| * of E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
|
* @see PEAR_ERROR_CALLBACK |
| *
|
* @see PEAR_ERROR_EXCEPTION |
| * When $mode is PEAR_ERROR_CALLBACK, this parameter is expected
|
* |
| * to be the callback function or method. A callback
|
* @since PHP 4.0.5 |
| * function is a string with the name of the function, a
|
*/ |
| * callback method is an array of two elements: the element
|
function setErrorHandling($mode = null, $options = null) |
| * at index 0 is the object, and the element at index 1 is
|
{ |
| * the name of the method to call in the object.
|
if (isset($this) && is_a($this, 'PEAR')) { |
| *
|
$setmode = &$this->_default_error_mode; |
| * When $mode is PEAR_ERROR_PRINT or PEAR_ERROR_DIE, this is
|
$setoptions = &$this->_default_error_options; |
| * a printf format string used when printing the error
|
} else { |
| * message.
|
$setmode = &$GLOBALS['_PEAR_default_error_mode']; |
| *
|
$setoptions = &$GLOBALS['_PEAR_default_error_options']; |
| * @access public
|
} |
| * @return void
|
|
| * @see PEAR_ERROR_RETURN
|
switch ($mode) { |
| * @see PEAR_ERROR_PRINT
|
case PEAR_ERROR_EXCEPTION: |
| * @see PEAR_ERROR_TRIGGER
|
case PEAR_ERROR_RETURN: |
| * @see PEAR_ERROR_DIE
|
case PEAR_ERROR_PRINT: |
| * @see PEAR_ERROR_CALLBACK
|
case PEAR_ERROR_TRIGGER: |
| * @see PEAR_ERROR_EXCEPTION
|
case PEAR_ERROR_DIE: |
| *
|
case null: |
| * @since PHP 4.0.5
|
$setmode = $mode; |
| */
|
$setoptions = $options; |
|
|
break; |
| function setErrorHandling($mode = null, $options = null)
|
|
| {
|
case PEAR_ERROR_CALLBACK: |
| if (isset($this) && is_a($this, 'PEAR')) {
|
$setmode = $mode; |
| $setmode = &$this->_default_error_mode;
|
// class/object method callback |
| $setoptions = &$this->_default_error_options;
|
if (is_callable($options)) { |
| } else {
|
$setoptions = $options; |
| $setmode = &$GLOBALS['_PEAR_default_error_mode'];
|
} else { |
| $setoptions = &$GLOBALS['_PEAR_default_error_options'];
|
trigger_error("invalid error callback", E_USER_WARNING); |
| }
|
} |
|
|
break; |
| switch ($mode) {
|
|
| case PEAR_ERROR_EXCEPTION:
|
default: |
| case PEAR_ERROR_RETURN:
|
trigger_error("invalid error mode", E_USER_WARNING); |
| case PEAR_ERROR_PRINT:
|
break; |
| case PEAR_ERROR_TRIGGER:
|
} |
| case PEAR_ERROR_DIE:
|
} |
| case null:
|
|
| $setmode = $mode;
|
/** |
| $setoptions = $options;
|
* This method is used to tell which errors you expect to get. |
| break;
|
* Expected errors are always returned with error mode |
|
|
* PEAR_ERROR_RETURN. Expected error codes are stored in a stack, |
| case PEAR_ERROR_CALLBACK:
|
* and this method pushes a new element onto it. The list of |
| $setmode = $mode;
|
* expected errors are in effect until they are popped off the |
| // class/object method callback
|
* stack with the popExpect() method. |
| if (is_callable($options)) {
|
* |
| $setoptions = $options;
|
* Note that this method can not be called statically |
| } else {
|
* |
| trigger_error("invalid error callback", E_USER_WARNING);
|
* @param mixed $code a single error code or an array of error codes to expect |
| }
|
* |
| break;
|
* @return int the new depth of the "expected errors" stack |
|
|
* @access public |
| default:
|
*/ |
| trigger_error("invalid error mode", E_USER_WARNING);
|
function expectError($code = '*') |
| break;
|
{ |
| }
|
if (is_array($code)) { |
| }
|
array_push($this->_expected_errors, $code); |
|
|
} else { |
| // }}}
|
array_push($this->_expected_errors, array($code)); |
| // {{{ expectError()
|
} |
|
|
return count($this->_expected_errors); |
| /**
|
} |
| * This method is used to tell which errors you expect to get.
|
|
| * Expected errors are always returned with error mode
|
/** |
| * PEAR_ERROR_RETURN. Expected error codes are stored in a stack,
|
* This method pops one element off the expected error codes |
| * and this method pushes a new element onto it. The list of
|
* stack. |
| * expected errors are in effect until they are popped off the
|
* |
| * stack with the popExpect() method.
|
* @return array the list of error codes that were popped |
| *
|
*/ |
| * Note that this method can not be called statically
|
function popExpect() |
| *
|
{ |
| * @param mixed $code a single error code or an array of error codes to expect
|
return array_pop($this->_expected_errors); |
| *
|
} |
| * @return int the new depth of the "expected errors" stack
|
|
| * @access public
|
/** |
| */
|
* This method checks unsets an error code if available |
| function expectError($code = '*')
|
* |
| {
|
* @param mixed error code |
| if (is_array($code)) {
|
* @return bool true if the error code was unset, false otherwise |
| array_push($this->_expected_errors, $code);
|
* @access private |
| } else {
|
* @since PHP 4.3.0 |
| array_push($this->_expected_errors, array($code));
|
*/ |
| }
|
function _checkDelExpect($error_code) |
| return sizeof($this->_expected_errors);
|
{ |
| }
|
$deleted = false; |
|
|
foreach ($this->_expected_errors as $key => $error_array) { |
| // }}}
|
if (in_array($error_code, $error_array)) { |
| // {{{ popExpect()
|
unset($this->_expected_errors[$key][array_search($error_code, $error_array)]); |
|
|
$deleted = true; |
| /**
|
} |
| * This method pops one element off the expected error codes
|
|
| * stack.
|
// clean up empty arrays |
| *
|
if (0 == count($this->_expected_errors[$key])) { |
| * @return array the list of error codes that were popped
|
unset($this->_expected_errors[$key]); |
| */
|
} |
| function popExpect()
|
} |
| {
|
|
| return array_pop($this->_expected_errors);
|
return $deleted; |
| }
|
} |
|
|
|
| // }}}
|
/** |
| // {{{ _checkDelExpect()
|
* This method deletes all occurences of the specified element from |
|
|
* the expected error codes stack. |
| /**
|
* |
| * This method checks unsets an error code if available
|
* @param mixed $error_code error code that should be deleted |
| *
|
* @return mixed list of error codes that were deleted or error |
| * @param mixed error code
|
* @access public |
| * @return bool true if the error code was unset, false otherwise
|
* @since PHP 4.3.0 |
| * @access private
|
*/ |
| * @since PHP 4.3.0
|
function delExpect($error_code) |
| */
|
{ |
| function _checkDelExpect($error_code)
|
$deleted = false; |
| {
|
if ((is_array($error_code) && (0 != count($error_code)))) { |
| $deleted = false;
|
// $error_code is a non-empty array here; we walk through it trying |
|
|
// to unset all values |
| foreach ($this->_expected_errors AS $key => $error_array) {
|
foreach ($error_code as $key => $error) { |
| if (in_array($error_code, $error_array)) {
|
$deleted = $this->_checkDelExpect($error) ? true : false; |
| unset($this->_expected_errors[$key][array_search($error_code, $error_array)]);
|
} |
| $deleted = true;
|
|
| }
|
return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME |
|
|
} elseif (!empty($error_code)) { |
| // clean up empty arrays
|
// $error_code comes alone, trying to unset it |
| if (0 == count($this->_expected_errors[$key])) {
|
if ($this->_checkDelExpect($error_code)) { |
| unset($this->_expected_errors[$key]);
|
return true; |
| }
|
} |
| }
|
|
| return $deleted;
|
return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME |
| }
|
} |
|
|
|
| // }}}
|
// $error_code is empty |
| // {{{ delExpect()
|
return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME |
|
|
} |
| /**
|
|
| * This method deletes all occurences of the specified element from
|
/** |
| * the expected error codes stack.
|
* This method is a wrapper that returns an instance of the |
| *
|
* configured error class with this object's default error |
| * @param mixed $error_code error code that should be deleted
|
* handling applied. If the $mode and $options parameters are not |
| * @return mixed list of error codes that were deleted or error
|
* specified, the object's defaults are used. |
| * @access public
|
* |
| * @since PHP 4.3.0
|
* @param mixed $message a text error message or a PEAR error object |
| */
|
* |
| function delExpect($error_code)
|
* @param int $code a numeric error code (it is up to your class |
| {
|
* to define these if you want to use codes) |
| $deleted = false;
|
* |
|
|
* @param int $mode One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT, |
| if ((is_array($error_code) && (0 != count($error_code)))) {
|
* PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE, |
| // $error_code is a non-empty array here;
|
* PEAR_ERROR_CALLBACK, PEAR_ERROR_EXCEPTION. |
| // we walk through it trying to unset all
|
* |
| // values
|
* @param mixed $options If $mode is PEAR_ERROR_TRIGGER, this parameter |
| foreach($error_code as $key => $error) {
|
* specifies the PHP-internal error level (one of |
| if ($this->_checkDelExpect($error)) {
|
* E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR). |
| $deleted = true;
|
* If $mode is PEAR_ERROR_CALLBACK, this |
| } else {
|
* parameter specifies the callback function or |
| $deleted = false;
|
* method. In other error modes this parameter |
| }
|
* is ignored. |
| }
|
* |
| return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
|
* @param string $userinfo If you need to pass along for example debug |
| } elseif (!empty($error_code)) {
|
* information, this parameter is meant for that. |
| // $error_code comes alone, trying to unset it
|
* |
| if ($this->_checkDelExpect($error_code)) {
|
* @param string $error_class The returned error object will be |
| return true;
|
* instantiated from this class, if specified. |
| } else {
|
* |
| return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME
|
* @param bool $skipmsg If true, raiseError will only pass error codes, |
| }
|
* the error message parameter will be dropped. |
| } else {
|
* |
| // $error_code is empty
|
* @access public |
| return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME
|
* @return object a PEAR error object |
| }
|
* @see PEAR::setErrorHandling |
| }
|
* @since PHP 4.0.5 |
|
|
*/ |
| // }}}
|
function &raiseError($message = null, |
| // {{{ raiseError()
|
$code = null, |
|
|
$mode = null, |
| /**
|
$options = null, |
| * This method is a wrapper that returns an instance of the
|
$userinfo = null, |
| * configured error class with this object's default error
|
$error_class = null, |
| * handling applied. If the $mode and $options parameters are not
|
$skipmsg = false) |
| * specified, the object's defaults are used.
|
{ |
| *
|
// The error is yet a PEAR error object |
| * @param mixed $message a text error message or a PEAR error object
|
if (is_object($message)) { |
| *
|
$code = $message->getCode(); |
| * @param int $code a numeric error code (it is up to your class
|
$userinfo = $message->getUserInfo(); |
| * to define these if you want to use codes)
|
$error_class = $message->getType(); |
| *
|
$message->error_message_prefix = ''; |
| * @param int $mode One of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT,
|
$message = $message->getMessage(); |
| * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE,
|
} |
| * PEAR_ERROR_CALLBACK, PEAR_ERROR_EXCEPTION.
|
|
| *
|
if ( |
| * @param mixed $options If $mode is PEAR_ERROR_TRIGGER, this parameter
|
isset($this) && |
| * specifies the PHP-internal error level (one of
|
isset($this->_expected_errors) && |
| * E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR).
|
count($this->_expected_errors) > 0 && |
| * If $mode is PEAR_ERROR_CALLBACK, this
|
count($exp = end($this->_expected_errors)) |
| * parameter specifies the callback function or
|
) { |
| * method. In other error modes this parameter
|
if ($exp[0] == "*" || |
| * is ignored.
|
(is_int(reset($exp)) && in_array($code, $exp)) || |
| *
|
(is_string(reset($exp)) && in_array($message, $exp)) |
| * @param string $userinfo If you need to pass along for example debug
|
) { |
| * information, this parameter is meant for that.
|
$mode = PEAR_ERROR_RETURN; |
| *
|
} |
| * @param string $error_class The returned error object will be
|
} |
| * instantiated from this class, if specified.
|
|
| *
|
// No mode given, try global ones |
| * @param bool $skipmsg If true, raiseError will only pass error codes,
|
if ($mode === null) { |
| * the error message parameter will be dropped.
|
// Class error handler |
| *
|
if (isset($this) && isset($this->_default_error_mode)) { |
| * @access public
|
$mode = $this->_default_error_mode; |
| * @return object a PEAR error object
|
$options = $this->_default_error_options; |
| * @see PEAR::setErrorHandling
|
// Global error handler |
| * @since PHP 4.0.5
|
} elseif (isset($GLOBALS['_PEAR_default_error_mode'])) { |
| */
|
$mode = $GLOBALS['_PEAR_default_error_mode']; |
| function &raiseError($message = null,
|
$options = $GLOBALS['_PEAR_default_error_options']; |
| $code = null,
|
} |
| $mode = null,
|
} |
| $options = null,
|
|
| $userinfo = null,
|
if ($error_class !== null) { |
| $error_class = null,
|
$ec = $error_class; |
| $skipmsg = false)
|
} elseif (isset($this) && isset($this->_error_class)) { |
| {
|
$ec = $this->_error_class; |
| // The error is yet a PEAR error object
|
} else { |
| if (is_object($message)) {
|
$ec = 'PEAR_Error'; |
| $code = $message->getCode();
|
} |
| $userinfo = $message->getUserInfo();
|
|
| $error_class = $message->getType();
|
if (intval(PHP_VERSION) < 5) { |
| $message->error_message_prefix = '';
|
// little non-eval hack to fix bug #12147 |
| $message = $message->getMessage();
|
include 'PEAR/FixPHP5PEARWarnings.php'; |
| }
|
return $a; |
|
|
} |
| if (isset($this) && isset($this->_expected_errors) && sizeof($this->_expected_errors) > 0 && sizeof($exp = end($this->_expected_errors))) {
|
|
| if ($exp[0] == "*" ||
|
if ($skipmsg) { |
| (is_int(reset($exp)) && in_array($code, $exp)) ||
|
$a = new $ec($code, $mode, $options, $userinfo); |
| (is_string(reset($exp)) && in_array($message, $exp))) {
|
} else { |
| $mode = PEAR_ERROR_RETURN;
|
$a = new $ec($message, $code, $mode, $options, $userinfo); |
| }
|
} |
| }
|
|
| // No mode given, try global ones
|
return $a; |
| if ($mode === null) {
|
} |
| // Class error handler
|
|
| if (isset($this) && isset($this->_default_error_mode)) {
|
/** |
| $mode = $this->_default_error_mode;
|
* Simpler form of raiseError with fewer options. In most cases |
| $options = $this->_default_error_options;
|
* message, code and userinfo are enough. |
| // Global error handler
|
* |
| } elseif (isset($GLOBALS['_PEAR_default_error_mode'])) {
|
* @param mixed $message a text error message or a PEAR error object |
| $mode = $GLOBALS['_PEAR_default_error_mode'];
|
* |
| $options = $GLOBALS['_PEAR_default_error_options'];
|
* @param int $code a numeric error code (it is up to your class |
| }
|
* to define these if you want to use codes) |
| }
|
* |
|
|
* @param string $userinfo If you need to pass along for example debug |
| if ($error_class !== null) {
|
* information, this parameter is meant for that. |
| $ec = $error_class;
|
* |
| } elseif (isset($this) && isset($this->_error_class)) {
|
* @access public |
| $ec = $this->_error_class;
|
* @return object a PEAR error object |
| } else {
|
* @see PEAR::raiseError |
| $ec = 'PEAR_Error';
|
*/ |
| }
|
function &throwError($message = null, $code = null, $userinfo = null) |
| if ($skipmsg) {
|
{ |
| $a = &new $ec($code, $mode, $options, $userinfo);
|
if (isset($this) && is_a($this, 'PEAR')) { |
| return $a;
|
$a = &$this->raiseError($message, $code, null, null, $userinfo); |
| } else {
|
return $a; |
| $a = &new $ec($message, $code, $mode, $options, $userinfo);
|
} |
| return $a;
|
|
| }
|
$a = &PEAR::raiseError($message, $code, null, null, $userinfo); |
| }
|
return $a; |
|
|
} |
| // }}}
|
|
| // {{{ throwError()
|
function staticPushErrorHandling($mode, $options = null) |
|
|
{ |
| /**
|
$stack = &$GLOBALS['_PEAR_error_handler_stack']; |
| * Simpler form of raiseError with fewer options. In most cases
|
$def_mode = &$GLOBALS['_PEAR_default_error_mode']; |
| * message, code and userinfo are enough.
|
$def_options = &$GLOBALS['_PEAR_default_error_options']; |
| *
|
$stack[] = array($def_mode, $def_options); |
| * @param string $message
|
switch ($mode) { |
| *
|
case PEAR_ERROR_EXCEPTION: |
| */
|
case PEAR_ERROR_RETURN: |
| function &throwError($message = null,
|
case PEAR_ERROR_PRINT: |
| $code = null,
|
case PEAR_ERROR_TRIGGER: |
| $userinfo = null)
|
case PEAR_ERROR_DIE: |
| {
|
case null: |
| if (isset($this) && is_a($this, 'PEAR')) {
|
$def_mode = $mode; |
| $a = &$this->raiseError($message, $code, null, null, $userinfo);
|
$def_options = $options; |
| return $a;
|
break; |
| } else {
|
|
| $a = &PEAR::raiseError($message, $code, null, null, $userinfo);
|
case PEAR_ERROR_CALLBACK: |
| return $a;
|
$def_mode = $mode; |
| }
|
// class/object method callback |
| }
|
if (is_callable($options)) { |
|
|
$def_options = $options; |
| // }}}
|
} else { |
| function staticPushErrorHandling($mode, $options = null)
|
trigger_error("invalid error callback", E_USER_WARNING); |
| {
|
} |
| $stack = &$GLOBALS['_PEAR_error_handler_stack'];
|
break; |
| $def_mode = &$GLOBALS['_PEAR_default_error_mode'];
|
|
| $def_options = &$GLOBALS['_PEAR_default_error_options'];
|
default: |
| $stack[] = array($def_mode, $def_options);
|
trigger_error("invalid error mode", E_USER_WARNING); |
| switch ($mode) {
|
break; |
| case PEAR_ERROR_EXCEPTION:
|
} |
| case PEAR_ERROR_RETURN:
|
$stack[] = array($mode, $options); |
| case PEAR_ERROR_PRINT:
|
return true; |
| case PEAR_ERROR_TRIGGER:
|
} |
| case PEAR_ERROR_DIE:
|
|
| case null:
|
function staticPopErrorHandling() |
| $def_mode = $mode;
|
{ |
| $def_options = $options;
|
$stack = &$GLOBALS['_PEAR_error_handler_stack']; |
| break;
|
$setmode = &$GLOBALS['_PEAR_default_error_mode']; |
|
|
$setoptions = &$GLOBALS['_PEAR_default_error_options']; |
| case PEAR_ERROR_CALLBACK:
|
array_pop($stack); |
| $def_mode = $mode;
|
list($mode, $options) = $stack[sizeof($stack) - 1]; |
| // class/object method callback
|
array_pop($stack); |
| if (is_callable($options)) {
|
switch ($mode) { |
| $def_options = $options;
|
case PEAR_ERROR_EXCEPTION: |
| } else {
|
case PEAR_ERROR_RETURN: |
| trigger_error("invalid error callback", E_USER_WARNING);
|
case PEAR_ERROR_PRINT: |
| }
|
case PEAR_ERROR_TRIGGER: |
| break;
|
case PEAR_ERROR_DIE: |
|
|
case null: |
| default:
|
$setmode = $mode; |
| trigger_error("invalid error mode", E_USER_WARNING);
|
$setoptions = $options; |
| break;
|
break; |
| }
|
|
| $stack[] = array($mode, $options);
|
case PEAR_ERROR_CALLBACK: |
| return true;
|
$setmode = $mode; |
| }
|
// class/object method callback |
|
|
if (is_callable($options)) { |
| function staticPopErrorHandling()
|
$setoptions = $options; |
| {
|
} else { |
| $stack = &$GLOBALS['_PEAR_error_handler_stack'];
|
trigger_error("invalid error callback", E_USER_WARNING); |
| $setmode = &$GLOBALS['_PEAR_default_error_mode'];
|
} |
| $setoptions = &$GLOBALS['_PEAR_default_error_options'];
|
break; |
| array_pop($stack);
|
|
| list($mode, $options) = $stack[sizeof($stack) - 1];
|
default: |
| array_pop($stack);
|
trigger_error("invalid error mode", E_USER_WARNING); |
| switch ($mode) {
|
break; |
| case PEAR_ERROR_EXCEPTION:
|
} |
| case PEAR_ERROR_RETURN:
|
return true; |
| case PEAR_ERROR_PRINT:
|
} |
| case PEAR_ERROR_TRIGGER:
|
|
| case PEAR_ERROR_DIE:
|
/** |
| case null:
|
* Push a new error handler on top of the error handler options stack. With this |
| $setmode = $mode;
|
* you can easily override the actual error handler for some code and restore |
| $setoptions = $options;
|
* it later with popErrorHandling. |
| break;
|
* |
|
|
* @param mixed $mode (same as setErrorHandling) |
| case PEAR_ERROR_CALLBACK:
|
* @param mixed $options (same as setErrorHandling) |
| $setmode = $mode;
|
* |
| // class/object method callback
|
* @return bool Always true |
| if (is_callable($options)) {
|
* |
| $setoptions = $options;
|
* @see PEAR::setErrorHandling |
| } else {
|
*/ |
| trigger_error("invalid error callback", E_USER_WARNING);
|
function pushErrorHandling($mode, $options = null) |
| }
|
{ |
| break;
|
$stack = &$GLOBALS['_PEAR_error_handler_stack']; |
|
|
if (isset($this) && is_a($this, 'PEAR')) { |
| default:
|
$def_mode = &$this->_default_error_mode; |
| trigger_error("invalid error mode", E_USER_WARNING);
|
$def_options = &$this->_default_error_options; |
| break;
|
} else { |
| }
|
$def_mode = &$GLOBALS['_PEAR_default_error_mode']; |
| return true;
|
$def_options = &$GLOBALS['_PEAR_default_error_options']; |
| }
|
} |
|
|
$stack[] = array($def_mode, $def_options); |
| // {{{ pushErrorHandling()
|
|
|
|
if (isset($this) && is_a($this, 'PEAR')) { |
| /**
|
$this->setErrorHandling($mode, $options); |
| * Push a new error handler on top of the error handler options stack. With this
|
} else { |
| * you can easily override the actual error handler for some code and restore
|
PEAR::setErrorHandling($mode, $options); |
| * it later with popErrorHandling.
|
} |
| *
|
$stack[] = array($mode, $options); |
| * @param mixed $mode (same as setErrorHandling)
|
return true; |
| * @param mixed $options (same as setErrorHandling)
|
} |
| *
|
|
| * @return bool Always true
|
/** |
| *
|
* Pop the last error handler used |
| * @see PEAR::setErrorHandling
|
* |
| */
|
* @return bool Always true |
| function pushErrorHandling($mode, $options = null)
|
* |
| {
|
* @see PEAR::pushErrorHandling |
| $stack = &$GLOBALS['_PEAR_error_handler_stack'];
|
*/ |
| if (isset($this) && is_a($this, 'PEAR')) {
|
function popErrorHandling() |
| $def_mode = &$this->_default_error_mode;
|
{ |
| $def_options = &$this->_default_error_options;
|
$stack = &$GLOBALS['_PEAR_error_handler_stack']; |
| } else {
|
array_pop($stack); |
| $def_mode = &$GLOBALS['_PEAR_default_error_mode'];
|
list($mode, $options) = $stack[sizeof($stack) - 1]; |
| $def_options = &$GLOBALS['_PEAR_default_error_options'];
|
array_pop($stack); |
| }
|
if (isset($this) && is_a($this, 'PEAR')) { |
| $stack[] = array($def_mode, $def_options);
|
$this->setErrorHandling($mode, $options); |
|
|
} else { |
| if (isset($this) && is_a($this, 'PEAR')) {
|
PEAR::setErrorHandling($mode, $options); |
| $this->setErrorHandling($mode, $options);
|
} |
| } else {
|
return true; |
| PEAR::setErrorHandling($mode, $options);
|
} |
| }
|
|
| $stack[] = array($mode, $options);
|
/** |
| return true;
|
* OS independant PHP extension load. Remember to take care |
| }
|
* on the correct extension name for case sensitive OSes. |
|
|
* |
| // }}}
|
* @param string $ext The extension name |
| // {{{ popErrorHandling()
|
* @return bool Success or not on the dl() call |
|
|
*/ |
| /**
|
function loadExtension($ext) |
| * Pop the last error handler used
|
{ |
| *
|
if (extension_loaded($ext)) { |
| * @return bool Always true
|
return true; |
| *
|
} |
| * @see PEAR::pushErrorHandling
|
|
| */
|
// if either returns true dl() will produce a FATAL error, stop that |
| function popErrorHandling()
|
if ( |
| {
|
function_exists('dl') === false || |
| $stack = &$GLOBALS['_PEAR_error_handler_stack'];
|
ini_get('enable_dl') != 1 || |
| array_pop($stack);
|
ini_get('safe_mode') == 1 |
| list($mode, $options) = $stack[sizeof($stack) - 1];
|
) { |
| array_pop($stack);
|
return false; |
| if (isset($this) && is_a($this, 'PEAR')) {
|
} |
| $this->setErrorHandling($mode, $options);
|
|
| } else {
|
if (OS_WINDOWS) { |
| PEAR::setErrorHandling($mode, $options);
|
$suffix = '.dll'; |
| }
|
} elseif (PHP_OS == 'HP-UX') { |
| return true;
|
$suffix = '.sl'; |
| }
|
} elseif (PHP_OS == 'AIX') { |
|
|
$suffix = '.a'; |
| // }}}
|
} elseif (PHP_OS == 'OSX') { |
| // {{{ loadExtension()
|
$suffix = '.bundle'; |
|
|
} else { |
| /**
|
$suffix = '.so'; |
| * OS independant PHP extension load. Remember to take care
|
} |
| * on the correct extension name for case sensitive OSes.
|
|
| *
|
return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix); |
| * @param string $ext The extension name
|
} |
| * @return bool Success or not on the dl() call
|
} |
| */
|
|
| function loadExtension($ext)
|
if (PEAR_ZE2) { |
| {
|
include_once 'PEAR5.php'; |
| if (!extension_loaded($ext)) {
|
} |
| // if either returns true dl() will produce a FATAL error, stop that
|
|
| if ((ini_get('enable_dl') != 1) || (ini_get('safe_mode') == 1)) {
|
function _PEAR_call_destructors() |
| return false;
|
{ |
| }
|
global $_PEAR_destructor_object_list; |
| if (OS_WINDOWS) {
|
if (is_array($_PEAR_destructor_object_list) && |
| $suffix = '.dll';
|
sizeof($_PEAR_destructor_object_list)) |
| } elseif (PHP_OS == 'HP-UX') {
|
{ |
| $suffix = '.sl';
|
reset($_PEAR_destructor_object_list); |
| } elseif (PHP_OS == 'AIX') {
|
if (PEAR_ZE2) { |
| $suffix = '.a';
|
$destructLifoExists = PEAR5::getStaticProperty('PEAR', 'destructlifo'); |
| } elseif (PHP_OS == 'OSX') {
|
} else { |
| $suffix = '.bundle';
|
$destructLifoExists = PEAR::getStaticProperty('PEAR', 'destructlifo'); |
| } else {
|
} |
| $suffix = '.so';
|
|
| }
|
if ($destructLifoExists) { |
| return @dl('php_'.$ext.$suffix) || @dl($ext.$suffix);
|
$_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list); |
| }
|
} |
| return true;
|
|
| }
|
while (list($k, $objref) = each($_PEAR_destructor_object_list)) { |
|
|
$classname = get_class($objref); |
| // }}}
|
while ($classname) { |
| }
|
$destructor = "_$classname"; |
|
|
if (method_exists($objref, $destructor)) { |
| // {{{ _PEAR_call_destructors()
|
$objref->$destructor(); |
|
|
break; |
| function _PEAR_call_destructors()
|
} else { |
| {
|
$classname = get_parent_class($classname); |
| global $_PEAR_destructor_object_list;
|
} |
| if (is_array($_PEAR_destructor_object_list) &&
|
} |
| sizeof($_PEAR_destructor_object_list))
|
} |
| {
|
// Empty the object list to ensure that destructors are |
| reset($_PEAR_destructor_object_list);
|
// not called more than once. |
| if (@PEAR::getStaticProperty('PEAR', 'destructlifo')) {
|
$_PEAR_destructor_object_list = array(); |
| $_PEAR_destructor_object_list = array_reverse($_PEAR_destructor_object_list);
|
} |
| }
|
|
| while (list($k, $objref) = each($_PEAR_destructor_object_list)) {
|
// Now call the shutdown functions |
| $classname = get_class($objref);
|
if ( |
| while ($classname) {
|
isset($GLOBALS['_PEAR_shutdown_funcs']) && |
| $destructor = "_$classname";
|
is_array($GLOBALS['_PEAR_shutdown_funcs']) && |
| if (method_exists($objref, $destructor)) {
|
!empty($GLOBALS['_PEAR_shutdown_funcs']) |
| $objref->$destructor();
|
) { |
| break;
|
foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) { |
| } else {
|
call_user_func_array($value[0], $value[1]); |
| $classname = get_parent_class($classname);
|
} |
| }
|
} |
| }
|
} |
| }
|
|
| // Empty the object list to ensure that destructors are
|
/** |
| // not called more than once.
|
* Standard PEAR error class for PHP 4 |
| $_PEAR_destructor_object_list = array();
|
* |
| }
|
* This class is supserseded by {@link PEAR_Exception} in PHP 5 |
|
|
* |
| // Now call the shutdown functions
|
* @category pear |
| if (is_array($GLOBALS['_PEAR_shutdown_funcs']) AND !empty($GLOBALS['_PEAR_shutdown_funcs'])) {
|
* @package PEAR |
| foreach ($GLOBALS['_PEAR_shutdown_funcs'] as $value) {
|
* @author Stig Bakken <ssb@php.net> |
| call_user_func_array($value[0], $value[1]);
|
* @author Tomas V.V. Cox <cox@idecnet.com> |
| }
|
* @author Gregory Beaver <cellog@php.net> |
| }
|
* @copyright 1997-2006 The PHP Group |
| }
|
* @license http://opensource.org/licenses/bsd-license.php New BSD License |
|
|
* @version Release: 1.9.3 |
| // }}}
|
* @link http://pear.php.net/manual/en/core.pear.pear-error.php |
| /**
|
* @see PEAR::raiseError(), PEAR::throwError() |
| * Standard PEAR error class for PHP 4
|
* @since Class available since PHP 4.0.2 |
| *
|
*/ |
| * This class is supserseded by {@link PEAR_Exception} in PHP 5
|
class PEAR_Error |
| *
|
{ |
| * @category pear
|
var $error_message_prefix = ''; |
| * @package PEAR
|
var $mode = PEAR_ERROR_RETURN; |
| * @author Stig Bakken <ssb@php.net>
|
var $level = E_USER_NOTICE; |
| * @author Tomas V.V. Cox <cox@idecnet.com>
|
var $code = -1; |
| * @author Gregory Beaver <cellog@php.net>
|
var $message = ''; |
| * @copyright 1997-2005 The PHP Group
|
var $userinfo = ''; |
| * @license http://www.php.net/license/3_0.txt PHP License 3.0
|
var $backtrace = null; |
| * @version Release: 1.4.5
|
|
| * @link http://pear.php.net/manual/en/core.pear.pear-error.php
|
/** |
| * @see PEAR::raiseError(), PEAR::throwError()
|
* PEAR_Error constructor |
| * @since Class available since PHP 4.0.2
|
* |
| */
|
* @param string $message message |
| class PEAR_Error
|
* |
| {
|
* @param int $code (optional) error code |
| // {{{ properties
|
* |
|
|
* @param int $mode (optional) error mode, one of: PEAR_ERROR_RETURN, |
| var $error_message_prefix = '';
|
* PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER, |
| var $mode = PEAR_ERROR_RETURN;
|
* PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION |
| var $level = E_USER_NOTICE;
|
* |
| var $code = -1;
|
* @param mixed $options (optional) error level, _OR_ in the case of |
| var $message = '';
|
* PEAR_ERROR_CALLBACK, the callback function or object/method |
| var $userinfo = '';
|
* tuple. |
| var $backtrace = null;
|
* |
|
|
* @param string $userinfo (optional) additional user/debug info |
| // }}}
|
* |
| // {{{ constructor
|
* @access public |
|
|
* |
| /**
|
*/ |
| * PEAR_Error constructor
|
function PEAR_Error($message = 'unknown error', $code = null, |
| *
|
$mode = null, $options = null, $userinfo = null) |
| * @param string $message message
|
{ |
| *
|
if ($mode === null) { |
| * @param int $code (optional) error code
|
$mode = PEAR_ERROR_RETURN; |
| *
|
} |
| * @param int $mode (optional) error mode, one of: PEAR_ERROR_RETURN,
|
$this->message = $message; |
| * PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER,
|
$this->code = $code; |
| * PEAR_ERROR_CALLBACK or PEAR_ERROR_EXCEPTION
|
$this->mode = $mode; |
| *
|
$this->userinfo = $userinfo; |
| * @param mixed $options (optional) error level, _OR_ in the case of
|
|
| * PEAR_ERROR_CALLBACK, the callback function or object/method
|
if (PEAR_ZE2) { |
| * tuple.
|
$skiptrace = PEAR5::getStaticProperty('PEAR_Error', 'skiptrace'); |
| *
|
} else { |
| * @param string $userinfo (optional) additional user/debug info
|
$skiptrace = PEAR::getStaticProperty('PEAR_Error', 'skiptrace'); |
| *
|
} |
| * @access public
|
|
| *
|
if (!$skiptrace) { |
| */
|
$this->backtrace = debug_backtrace(); |
| function PEAR_Error($message = 'unknown error', $code = null,
|
if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) { |
| $mode = null, $options = null, $userinfo = null)
|
unset($this->backtrace[0]['object']); |
| {
|
} |
| if ($mode === null) {
|
} |
| $mode = PEAR_ERROR_RETURN;
|
|
| }
|
if ($mode & PEAR_ERROR_CALLBACK) { |
| $this->message = $message;
|
$this->level = E_USER_NOTICE; |
| $this->code = $code;
|
$this->callback = $options; |
| $this->mode = $mode;
|
} else { |
| $this->userinfo = $userinfo;
|
if ($options === null) { |
| if (function_exists("debug_backtrace")) {
|
$options = E_USER_NOTICE; |
| if (@!PEAR::getStaticProperty('PEAR_Error', 'skiptrace')) {
|
} |
| $this->backtrace = debug_backtrace();
|
|
| }
|
$this->level = $options; |
| }
|
$this->callback = null; |
| if ($mode & PEAR_ERROR_CALLBACK) {
|
} |
| $this->level = E_USER_NOTICE;
|
|
| $this->callback = $options;
|
if ($this->mode & PEAR_ERROR_PRINT) { |
| } else {
|
if (is_null($options) || is_int($options)) { |
| if ($options === null) {
|
$format = "%s"; |
| $options = E_USER_NOTICE;
|
} else { |
| }
|
$format = $options; |
| $this->level = $options;
|
} |
| $this->callback = null;
|
|
| }
|
printf($format, $this->getMessage()); |
| if ($this->mode & PEAR_ERROR_PRINT) {
|
} |
| if (is_null($options) || is_int($options)) {
|
|
| $format = "%s";
|
if ($this->mode & PEAR_ERROR_TRIGGER) { |
| } else {
|
trigger_error($this->getMessage(), $this->level); |
| $format = $options;
|
} |
| }
|
|
| printf($format, $this->getMessage());
|
if ($this->mode & PEAR_ERROR_DIE) { |
| }
|
$msg = $this->getMessage(); |
| if ($this->mode & PEAR_ERROR_TRIGGER) {
|
if (is_null($options) || is_int($options)) { |
| trigger_error($this->getMessage(), $this->level);
|
$format = "%s"; |
| }
|
if (substr($msg, -1) != "\n") { |
| if ($this->mode & PEAR_ERROR_DIE) {
|
$msg .= "\n"; |
| $msg = $this->getMessage();
|
} |
| if (is_null($options) || is_int($options)) {
|
} else { |
| $format = "%s";
|
$format = $options; |
| if (substr($msg, -1) != "\n") {
|
} |
| $msg .= "\n";
|
die(sprintf($format, $msg)); |
| }
|
} |
| } else {
|
|
| $format = $options;
|
if ($this->mode & PEAR_ERROR_CALLBACK && is_callable($this->callback)) { |
| }
|
call_user_func($this->callback, $this); |
| die(sprintf($format, $msg));
|
} |
| }
|
|
| if ($this->mode & PEAR_ERROR_CALLBACK) {
|
if ($this->mode & PEAR_ERROR_EXCEPTION) { |
| if (is_callable($this->callback)) {
|
trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING); |
| call_user_func($this->callback, $this);
|
eval('$e = new Exception($this->message, $this->code);throw($e);'); |
| }
|
} |
| }
|
} |
| if ($this->mode & PEAR_ERROR_EXCEPTION) {
|
|
| trigger_error("PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
|
/** |
| eval('$e = new Exception($this->message, $this->code);throw($e);');
|
* Get the error mode from an error object. |
| }
|
* |
| }
|
* @return int error mode |
|
|
* @access public |
| // }}}
|
*/ |
| // {{{ getMode()
|
function getMode() |
|
|
{ |
| /**
|
return $this->mode; |
| * Get the error mode from an error object.
|
} |
| *
|
|
| * @return int error mode
|
/** |
| * @access public
|
* Get the callback function/method from an error object. |
| */
|
* |
| function getMode() {
|
* @return mixed callback function or object/method array |
| return $this->mode;
|
* @access public |
| }
|
*/ |
|
|
function getCallback() |
| // }}}
|
{ |
| // {{{ getCallback()
|
return $this->callback; |
|
|
} |
| /**
|
|
| * Get the callback function/method from an error object.
|
/** |
| *
|
* Get the error message from an error object. |
| * @return mixed callback function or object/method array
|
* |
| * @access public
|
* @return string full error message |
| */
|
* @access public |
| function getCallback() {
|
*/ |
| return $this->callback;
|
function getMessage() |
| }
|
{ |
|
|
return ($this->error_message_prefix . $this->message); |
| // }}}
|
} |
| // {{{ getMessage()
|
|
|
|
/** |
|
|
* Get error code from an error object |
| /**
|
* |
| * Get the error message from an error object.
|
* @return int error code |
| *
|
* @access public |
| * @return string full error message
|
*/ |
| * @access public
|
function getCode() |
| */
|
{ |
| function getMessage()
|
return $this->code; |
| {
|
} |
| return ($this->error_message_prefix . $this->message);
|
|
| }
|
/** |
|
|
* Get the name of this error/exception. |
|
|
* |
| // }}}
|
* @return string error/exception name (type) |
| // {{{ getCode()
|
* @access public |
|
|
*/ |
| /**
|
function getType() |
| * Get error code from an error object
|
{ |
| *
|
return get_class($this); |
| * @return int error code
|
} |
| * @access public
|
|
| */
|
/** |
| function getCode()
|
* Get additional user-supplied information. |
| {
|
* |
| return $this->code;
|
* @return string user-supplied information |
| }
|
* @access public |
|
|
*/ |
| // }}}
|
function getUserInfo() |
| // {{{ getType()
|
{ |
|
|
return $this->userinfo; |
| /**
|
} |
| * Get the name of this error/exception.
|
|
| *
|
/** |
| * @return string error/exception name (type)
|
* Get additional debug information supplied by the application. |
| * @access public
|
* |
| */
|
* @return string debug information |
| function getType()
|
* @access public |
| {
|
*/ |
| return get_class($this);
|
function getDebugInfo() |
| }
|
{ |
|
|
return $this->getUserInfo(); |
| // }}}
|
} |
| // {{{ getUserInfo()
|
|
|
|
/** |
| /**
|
* Get the call backtrace from where the error was generated. |
| * Get additional user-supplied information.
|
* Supported with PHP 4.3.0 or newer. |
| *
|
* |
| * @return string user-supplied information
|
* @param int $frame (optional) what frame to fetch |
| * @access public
|
* @return array Backtrace, or NULL if not available. |
| */
|
* @access public |
| function getUserInfo()
|
*/ |
| {
|
function getBacktrace($frame = null) |
| return $this->userinfo;
|
{ |
| }
|
if (defined('PEAR_IGNORE_BACKTRACE')) { |
|
|
return null; |
| // }}}
|
} |
| // {{{ getDebugInfo()
|
if ($frame === null) { |
|
|
return $this->backtrace; |
| /**
|
} |
| * Get additional debug information supplied by the application.
|
return $this->backtrace[$frame]; |
| *
|
} |
| * @return string debug information
|
|
| * @access public
|
function addUserInfo($info) |
| */
|
{ |
| function getDebugInfo()
|
if (empty($this->userinfo)) { |
| {
|
$this->userinfo = $info; |
| return $this->getUserInfo();
|
} else { |
| }
|
$this->userinfo .= " ** $info"; |
|
|
} |
| // }}}
|
} |
| // {{{ getBacktrace()
|
|
|
|
function __toString() |
| /**
|
{ |
| * Get the call backtrace from where the error was generated.
|
return $this->getMessage(); |
| * Supported with PHP 4.3.0 or newer.
|
} |
| *
|
|
| * @param int $frame (optional) what frame to fetch
|
/** |
| * @return array Backtrace, or NULL if not available.
|
* Make a string representation of this object. |
| * @access public
|
* |
| */
|
* @return string a string with an object summary |
| function getBacktrace($frame = null)
|
* @access public |
| {
|
*/ |
| if (defined('PEAR_IGNORE_BACKTRACE')) {
|
function toString() |
| return null;
|
{ |
| }
|
$modes = array(); |
| if ($frame === null) {
|
$levels = array(E_USER_NOTICE => 'notice', |
| return $this->backtrace;
|
E_USER_WARNING => 'warning', |
| }
|
E_USER_ERROR => 'error'); |
| return $this->backtrace[$frame];
|
if ($this->mode & PEAR_ERROR_CALLBACK) { |
| }
|
if (is_array($this->callback)) { |
|
|
$callback = (is_object($this->callback[0]) ? |
| // }}}
|
strtolower(get_class($this->callback[0])) : |
| // {{{ addUserInfo()
|
$this->callback[0]) . '::' . |
|
|
$this->callback[1]; |
| function addUserInfo($info)
|
} else { |
| {
|
$callback = $this->callback; |
| if (empty($this->userinfo)) {
|
} |
| $this->userinfo = $info;
|
return sprintf('[%s: message="%s" code=%d mode=callback '. |
| } else {
|
'callback=%s prefix="%s" info="%s"]', |
| $this->userinfo .= " ** $info";
|
strtolower(get_class($this)), $this->message, $this->code, |
| }
|
$callback, $this->error_message_prefix, |
| }
|
$this->userinfo); |
|
|
} |
| // }}}
|
if ($this->mode & PEAR_ERROR_PRINT) { |
| // {{{ toString()
|
$modes[] = 'print'; |
|
|
} |
| /**
|
if ($this->mode & PEAR_ERROR_TRIGGER) { |
| * Make a string representation of this object.
|
$modes[] = 'trigger'; |
| *
|
} |
| * @return string a string with an object summary
|
if ($this->mode & PEAR_ERROR_DIE) { |
| * @access public
|
$modes[] = 'die'; |
| */
|
} |
| function toString() {
|
if ($this->mode & PEAR_ERROR_RETURN) { |
| $modes = array();
|
$modes[] = 'return'; |
| $levels = array(E_USER_NOTICE => 'notice',
|
} |
| E_USER_WARNING => 'warning',
|
return sprintf('[%s: message="%s" code=%d mode=%s level=%s '. |
| E_USER_ERROR => 'error');
|
'prefix="%s" info="%s"]', |
| if ($this->mode & PEAR_ERROR_CALLBACK) {
|
strtolower(get_class($this)), $this->message, $this->code, |
| if (is_array($this->callback)) {
|
implode("|", $modes), $levels[$this->level], |
| $callback = (is_object($this->callback[0]) ?
|
$this->error_message_prefix, |
| strtolower(get_class($this->callback[0])) :
|
$this->userinfo); |
| $this->callback[0]) . '::' .
|
} |
| $this->callback[1];
|
} |
| } else {
|
|
| $callback = $this->callback;
|
/* |
| }
|
* Local Variables: |
| return sprintf('[%s: message="%s" code=%d mode=callback '.
|
* mode: php |
| 'callback=%s prefix="%s" info="%s"]',
|
* tab-width: 4 |
| strtolower(get_class($this)), $this->message, $this->code,
|
* c-basic-offset: 4 |
| $callback, $this->error_message_prefix,
|
* End: |
| $this->userinfo);
|
*/ |
| }
|
|
| if ($this->mode & PEAR_ERROR_PRINT) {
|
|
| $modes[] = 'print';
|
|
| }
|
|
| if ($this->mode & PEAR_ERROR_TRIGGER) {
|
|
| $modes[] = 'trigger';
|
|
| }
|
|
| if ($this->mode & PEAR_ERROR_DIE) {
|
|
| $modes[] = 'die';
|
|
| }
|
|
| if ($this->mode & PEAR_ERROR_RETURN) {
|
|
| $modes[] = 'return';
|
|
| }
|
|
| return sprintf('[%s: message="%s" code=%d mode=%s level=%s '.
|
|
| 'prefix="%s" info="%s"]',
|
|
| strtolower(get_class($this)), $this->message, $this->code,
|
|
| implode("|", $modes), $levels[$this->level],
|
|
| $this->error_message_prefix,
|
|
| $this->userinfo);
|
|
| }
|
|
|
|
|
| // }}}
|
|
| }
|
|
|
|
|
| /*
|
|
| * Local Variables:
|
|
| * mode: php
|
|
| * tab-width: 4
|
|
| * c-basic-offset: 4
|
|
| * End:
|
|
| */
|
|
| ?>
|
|