pear.php

来自「通达OA2007SE源代码 非常好的」· PHP 代码 · 共 463 行

PHP
463
字号
<?
  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).'
');
      }
      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;
        }
        $classname = get_parent_class ($classname);
      }
    }
    function _pear ()
    {
      if ($this->_debug)
      {
        printf ('PEAR destructor called, class=%s
', get_class ($this));
      }
    }
    function iserror ($data)
    {
      return (bool)(is_object ($data) AND ((get_class ($data) == 'pear_error') OR 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 = &$GLOBALS['_PEAR_default_error_mode'];
        $setoptions = &$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;
          break;
        }
        case PEAR_ERROR_CALLBACK:
        {
          $setmode = $mode;
          if (((is_string ($options) AND function_exists ($options)) OR (is_array ($options) AND method_exists ($options[0], $options[1]))))
          {
            $setoptions = $options;
            break;
          }
          else
          {
            trigger_error ('invalid error callback', E_USER_WARNING);
            break;
          }
          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) AND isset ($this->_expected_errors)) AND (0 < sizeof ($this->_expected_errors))) AND sizeof ($exp = end ($this->_expected_errors))))
      {
        if (((($exp[0] == '*') OR (is_int (reset ($exp)) AND in_array ($code, $exp))) OR (is_string (reset ($exp)) AND in_array ($message, $exp))))
        {
          $mode = PEAR_ERROR_RETURN;
        }
      }
      if (($mode === null))
      {
        if ((isset ($this) AND isset ($this->_default_error_mode)))
        {
          $mode = $this->_default_error_mode;
        }
        else
        {
          $mode = $GLOBALS['_PEAR_default_error_mode'];
        }
      }
      if ((($mode == PEAR_ERROR_TRIGGER) AND ($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))
      {
        if ((!is_string ($options) AND !(((is_array ($options) AND (sizeof ($options) == 2)) AND is_object ($options[0])) AND is_string ($options[1]))))
        {
          if ((isset ($this) AND isset ($this->_default_error_options)))
          {
            $options = $this->_default_error_options;
          }
          else
          {
            $options = $GLOBALS['_PEAR_default_error_options'];
          }
        }
      }
      else
      {
        if (($options === null))
        {
          if (isset ($this))
          {
            if (isset ($this->_default_error_options))
            {
              $options = $this->_default_error_options;
            }
          }
          else
          {
            $options = $GLOBALS['_PEAR_default_error_options'];
          }
        }
      }
      if (($error_class !== null))
      {
        $ec = $error_class;
      }
      else
      {
        if ((isset ($this) AND 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 = &$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['_PEAR_default_error_mode'];
          $def_options = &$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;
    }
    function poperrorhandling ()
    {
      $stack = &$GLOBALS['_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) OR 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) OR is_int ($options)))
        {
          $format = '%s';
          if ((substr ($msg, -1) != '
'))
          {
            ($msg .= '
');
          }
        }
        else
        {
          $format = $options;
        }
        exit (sprintf ($format, $msg));
      }
      if (($this->mode & PEAR_ERROR_CALLBACK))
      {
        if ((is_string ($this->callback) AND strlen ($this->callback)))
        {
          call_user_func ($this->callback, $this);
        }
        else
        {
          if (((((is_array ($this->callback) AND (sizeof ($this->callback) == 2)) AND is_object ($this->callback[0])) AND is_string ($this->callback[1])) AND 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 (E_USER_NOTICE => 'notice', E_USER_WARNING => 'warning', E_USER_ERROR => '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) AND 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 ();
            break;
          }
          $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 + =
减小字号Ctrl + -
显示快捷键?