📄 pear.php
字号:
<?php
class pear
{
var $_debug = false;
var $_default_error_mode = null;
var $_default_error_options = null;
var $_default_error_handler = "";
var $_error_class = "PEAR_Error";
var $_expected_errors = array( );
function pear( $error_class = null )
{
$classname = get_class( $this );
if ( $this->_debug )
{
print "PEAR constructor called, class={$classname}\n";
}
if ( $error_class !== null )
{
$this->_error_class = $error_class;
}
while ( $classname )
{
$destructor = "_{$classname}";
if ( method_exists( $this, $destructor ) )
{
global $_PEAR_destructor_object_list;
$_PEAR_destructor_object_list[] =& $this;
break;
}
else
{
$classname = get_parent_class( $classname );
}
}
}
function _pear( )
{
if ( $this->_debug )
{
printf( "PEAR destructor called, class=%s\n", get_class( $this ) );
}
}
function iserror( $data )
{
return ( string )( is_object( $data ) && ( get_class( $data ) == "pear_error" || is_subclass_of( $data, "pear_error" ) ) );
}
function seterrorhandling( $mode = null, $options = null )
{
if ( isset( $this ) )
{
$setmode =& $this->_default_error_mode;
$setoptions =& $this->_default_error_options;
}
else
{
$setmode =& $_PEAR_default_error_mode;
$setoptions =& $_PEAR_default_error_options;
}
switch ( $mode )
{
case PEAR_ERROR_RETURN :
case PEAR_ERROR_PRINT :
case PEAR_ERROR_TRIGGER :
case PEAR_ERROR_DIE :
case null :
$setmode = $mode;
$setoptions = $options;
break;
case PEAR_ERROR_CALLBACK :
$setmode = $mode;
if ( is_string( $options ) && function_exists( $options ) || is_array( $options ) && method_exists( $options[0], $options[1] ) )
{
$setoptions = $options;
}
else
{
trigger_error( "invalid error callback", E_USER_WARNING );
break;
}
default :
trigger_error( "invalid error mode", E_USER_WARNING );
break;
}
}
function expecterror( $code = "*" )
{
if ( is_array( $code ) )
{
array_push( $this->_expected_errors, $code );
}
else
{
array_push( $this->_expected_errors, array(
$code
) );
}
return sizeof( $this->_expected_errors );
}
function popexpect( )
{
return array_pop( $this->_expected_errors );
}
function &raiseerror( $message = null, $code = null, $mode = null, $options = null, $userinfo = null, $error_class = null, $skipmsg = false )
{
if ( is_object( $message ) )
{
$code = $message->getcode( );
$userinfo = $message->getuserinfo( );
$error_class = $message->gettype( );
$message = $message->getmessage( );
}
if ( isset( $this ) && isset( $this->_expected_errors ) && 0 < sizeof( $this->_expected_errors ) && sizeof( $exp = end( $this->_expected_errors ) ) && ( $exp[0] == "*" || is_int( reset( $exp ) ) && in_array( $code, $exp ) || is_string( reset( $exp ) ) && in_array( $message, $exp ) ) )
{
$mode = PEAR_ERROR_RETURN;
}
if ( $mode === null )
{
if ( isset( $this ) && isset( $this->_default_error_mode ) )
{
$mode = $this->_default_error_mode;
}
else
{
$mode = $_PEAR_default_error_mode;
}
}
if ( $mode == PEAR_ERROR_TRIGGER && $options === null )
{
if ( isset( $this ) )
{
if ( isset( $this->_default_error_options ) )
{
$options = $this->_default_error_options;
}
}
else
{
$options = $_PEAR_default_error_options;
}
}
if ( $mode == PEAR_ERROR_CALLBACK )
{
if ( !is_string( $options ) && !( is_array( $options ) && sizeof( $options ) == 2 && is_object( $options[0] ) && is_string( $options[1] ) ) )
{
if ( isset( $this ) && isset( $this->_default_error_options ) )
{
$options = $this->_default_error_options;
}
else
{
$options = $_PEAR_default_error_options;
}
}
}
else if ( $options === null )
{
if ( isset( $this ) )
{
if ( isset( $this->_default_error_options ) )
{
$options = $this->_default_error_options;
}
}
else
{
$options = $_PEAR_default_error_options;
}
}
if ( $error_class !== null )
{
$ec = $error_class;
}
else if ( isset( $this ) && isset( $this->_error_class ) )
{
$ec = $this->_error_class;
}
else
{
$ec = "PEAR_Error";
}
if ( $skipmsg )
{
return new $ec( $code, $mode, $options, $userinfo );
}
else
{
return new $ec( $message, $code, $mode, $options, $userinfo );
}
}
function pusherrorhandling( $mode, $options = null )
{
$stack =& $_PEAR_error_handler_stack;
if ( !is_array( $stack ) )
{
if ( isset( $this ) )
{
$def_mode =& $this->_default_error_mode;
$def_options =& $this->_default_error_options;
}
else
{
$def_mode =& $_PEAR_default_error_mode;
$def_options =& $_PEAR_default_error_options;
}
$stack = array( );
$stack[] = array(
$def_mode,
$def_options
);
}
if ( isset( $this ) )
{
$this->seterrorhandling( $mode, $options );
}
else
{
pear::seterrorhandling( $mode, $options );
}
$stack[] = array(
$mode,
$options
);
return true;
}
function poperrorhandling( )
{
$stack =& $_PEAR_error_handler_stack;
array_pop( $stack );
list( $mode, $options ) = $stack[sizeof( $stack ) - 1];
if ( isset( $this ) )
{
$this->seterrorhandling( $mode, $options );
}
else
{
pear::seterrorhandling( $mode, $options );
}
return true;
}
}
class pear_error
{
var $error_message_prefix = "";
var $mode = PEAR_ERROR_RETURN;
var $level = E_USER_NOTICE;
var $code = -1;
var $message = "";
var $userinfo = "";
function pear_error( $message = "unknown error", $code = null, $mode = null, $options = null, $userinfo = null )
{
if ( $mode === null )
{
$mode = PEAR_ERROR_RETURN;
}
$this->message = $message;
$this->code = $code;
$this->mode = $mode;
$this->userinfo = $userinfo;
if ( $mode & PEAR_ERROR_CALLBACK )
{
$this->level = E_USER_NOTICE;
$this->callback = $options;
}
else
{
if ( $options === null )
{
$options = E_USER_NOTICE;
}
$this->level = $options;
$this->callback = null;
}
if ( $this->mode & PEAR_ERROR_PRINT )
{
if ( is_null( $options ) || is_int( $options ) )
{
$format = "%s";
}
else
{
$format = $options;
}
printf( $format, $this->getmessage( ) );
}
if ( $this->mode & PEAR_ERROR_TRIGGER )
{
trigger_error( $this->getmessage( ), $this->level );
}
if ( $this->mode & PEAR_ERROR_DIE )
{
$msg = $this->getmessage( );
if ( is_null( $options ) || is_int( $options ) )
{
$format = "%s";
if ( substr( $msg, -1 ) != "\n" )
{
$msg .= "\n";
}
}
else
{
$format = $options;
}
exit( sprintf( $format, $msg ) );
}
if ( $this->mode & PEAR_ERROR_CALLBACK )
{
if ( is_string( $this->callback ) && strlen( $this->callback ) )
{
call_user_func( $this->callback, $this );
}
else if ( is_array( $this->callback ) && sizeof( $this->callback ) == 2 && is_object( $this->callback[0] ) && is_string( $this->callback[1] ) && strlen( $this->callback[1] ) )
{
@call_user_method( $this->callback[1], $this->callback[0], $this );
}
}
}
function getmode( )
{
return $this->mode;
}
function getcallback( )
{
return $this->callback;
}
function getmessage( )
{
return $this->error_message_prefix.$this->message;
}
function getcode( )
{
return $this->code;
}
function gettype( )
{
return get_class( $this );
}
function getuserinfo( )
{
return $this->userinfo;
}
function getdebuginfo( )
{
return $this->getuserinfo( );
}
function adduserinfo( $info )
{
if ( empty( $this->userinfo ) )
{
$this->userinfo = $info;
}
else
{
$this->userinfo .= " ** {$info}";
}
}
function tostring( )
{
$modes = array( );
$levels = array( "notice", "warning", "error" );
if ( $this->mode & PEAR_ERROR_CALLBACK )
{
if ( is_array( $this->callback ) )
{
$callback = get_class( $this->callback[0] )."::".$this->callback[1];
}
else
{
$callback = $this->callback;
}
return sprintf( "[%s: message=\"%s\" code=%d mode=callback callback=%s prefix=\"%s\" info=\"%s\"]", get_class( $this ), $this->message, $this->code, $callback, $this->error_message_prefix, $this->userinfo );
}
if ( $this->mode & PEAR_ERROR_CALLBACK )
{
$modes[] = "callback";
}
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\"]", get_class( $this ), $this->message, $this->code, implode( "|", $modes ), $levels[$this->level], $this->error_message_prefix, $this->userinfo );
}
}
function _pear_call_destructors( )
{
global $_PEAR_destructor_object_list;
if ( is_array( $_PEAR_destructor_object_list ) && sizeof( $_PEAR_destructor_object_list ) )
{
reset( $_PEAR_destructor_object_list );
while ( list( $k, $objref ) = each( $_PEAR_destructor_object_list ) )
{
$classname = get_class( $objref );
while ( $classname )
{
$destructor = "_{$classname}";
if ( method_exists( $objref, $destructor ) )
{
$objref->$destructor( );
continue;
}
else
{
$classname = get_parent_class( $classname );
}
}
}
$_PEAR_destructor_object_list = array( );
}
}
define( "PEAR_ERROR_RETURN", 1 );
define( "PEAR_ERROR_PRINT", 2 );
define( "PEAR_ERROR_TRIGGER", 4 );
define( "PEAR_ERROR_DIE", 8 );
define( "PEAR_ERROR_CALLBACK", 16 );
if ( substr( PHP_OS, 0, 3 ) == "WIN" )
{
define( "OS_WINDOWS", true );
define( "OS_UNIX", false );
define( "PEAR_OS", "Windows" );
}
else
{
define( "OS_WINDOWS", false );
define( "OS_UNIX", true );
define( "PEAR_OS", "Unix" );
}
$GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_RETURN;
$GLOBALS['_PEAR_default_error_options'] = E_USER_NOTICE;
$GLOBALS['_PEAR_default_error_callback'] = "";
$GLOBALS['_PEAR_destructor_object_list'] = array( );
register_shutdown_function( "_PEAR_call_destructors" );
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -