📄 pear.php
字号:
<?php
class PEAR
{
public $_debug = FALSE;
public $_default_error_mode = NULL;
public $_default_error_options = NULL;
public $_default_error_handler = "";
public $_error_class = "PEAR_Error";
public $_expected_errors = array( );
public function PEAR( $error_class = NULL )
{
$classname = get_class( $this );
if ( $this->_debug )
{
echo "PEAR constructor called, class=";
echo $classname;
echo "\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;
}
else
{
$classname = get_parent_class( $classname );
}
}
}
public function _PEAR( )
{
if ( $this->_debug )
{
printf( "PEAR destructor called, class=%s\n", get_class( $this ) );
}
}
public function isError( $data )
{
return is_object( $data ) && ( get_class( $data ) == "pear_error" || is_subclass_of( $data, "pear_error" ) );
}
public function setErrorHandling( $mode = NULL, $options = NULL )
{
if ( isset( $this ) )
{
$setmode =& $this->_default_error_mode;
$setoptions =& $this->_default_error_options;
}
else
{
$setmode =& $GLOBALS['GLOBALS']['_PEAR_default_error_mode'];
$setoptions =& $GLOBALS['GLOBALS']['_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;
return;
case PEAR_ERROR_CALLBACK :
$setmode = $mode;
if ( is_string( $options ) )
{
}
if ( function_exists( $options ) || is_array( $options ) && method_exists( $options[0], $options[1] ) )
{
$setoptions = $options;
}
else
{
trigger_error( "invalid error callback", E_USER_WARNING );
return;
}
}
trigger_error( "invalid error mode", E_USER_WARNING );
}
public 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 );
}
public function popExpect( )
{
return array_pop( &$this->_expected_errors );
}
public 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 = $GLOBALS['_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 = $GLOBALS['_PEAR_default_error_options'];
}
}
if ( $mode == PEAR_ERROR_CALLBACK )
{
do
{
if ( !is_string( $options ) )
{
if ( is_array( $options ) )
{
}
if ( sizeof( $options ) == 2 && is_object( $options[0] ) && is_string( $options[1] ) )
{
break;
}
else
{
if ( isset( $this ) && isset( $this->_default_error_options ) )
{
$options = $this->_default_error_options;
break;
}
else
{
$options = $GLOBALS['_PEAR_default_error_options'];
}
}
}
}
else if ( $options === NULL )
{
if ( isset( $this ) )
{
if ( !isset( $this->_default_error_options ) )
{
break;
}
$options = $this->_default_error_options;
}
else
{
$options = $GLOBALS['_PEAR_default_error_options'];
}
} while ( 0 );
}
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 )
{
( $code, $mode, $options, $userinfo );
return new $ec( );
}
( $message, $code, $mode, $options, $userinfo );
return new $ec( );
}
public function pushErrorHandling( $mode, $options = NULL )
{
$stack =& $GLOBALS['GLOBALS']['_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 =& $GLOBALS['GLOBALS']['_PEAR_default_error_mode'];
$def_options =& $GLOBALS['GLOBALS']['_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;
}
public function popErrorHandling( )
{
$stack =& $GLOBALS['GLOBALS']['_PEAR_error_handler_stack'];
array_pop( &$stack );
list( $mode, $options ) = $stack[sizeof( $stack ) - 1];
if ( isset( $this ) )
{
$this->setErrorHandling( $mode, $options );
return TRUE;
}
PEAR::seterrorhandling( $mode, $options );
return TRUE;
}
}
class PEAR_Error
{
public $error_message_prefix = "";
public $mode = PEAR_ERROR_RETURN;
public $level = E_USER_NOTICE;
public $code = -1;
public $message = "";
public $userinfo = "";
public 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 );
}
}
}
public function getMode( )
{
return $this->mode;
}
public function getCallback( )
{
return $this->callback;
}
public function getMessage( )
{
return $this->error_message_prefix.$this->message;
}
public function getCode( )
{
return $this->code;
}
public function getType( )
{
return get_class( $this );
}
public function getUserInfo( )
{
return $this->userinfo;
}
public function getDebugInfo( )
{
return $this->getUserInfo( );
}
public function addUserInfo( $info )
{
if ( empty( $this->userinfo ) )
{
$this->userinfo = $info;
}
else
{
$this->userinfo .= " ** ".$info;
}
}
public 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 );
do
{
while ( list( $k, $objref ) = each( &$_PEAR_destructor_object_list ) )
{
$classname = get_class( $objref );
if ( $classname )
{
$destructor = "_".$classname;
if ( !method_exists( $objref, $destructor ) )
{
break;
}
$objref->$destructor( );
}
}
$classname = get_parent_class( $classname );
} while ( 1 );
$_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['GLOBALS']['_PEAR_default_error_mode'] = PEAR_ERROR_RETURN;
$GLOBALS['GLOBALS']['_PEAR_default_error_options'] = E_USER_NOTICE;
$GLOBALS['GLOBALS']['_PEAR_default_error_callback'] = "";
$GLOBALS['GLOBALS']['_PEAR_destructor_object_list'] = array( );
register_shutdown_function( "_PEAR_call_destructors" );
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -