Example #1
0
 /**
  * PEAR_Error constructor
  *
  * @param string $message  message
  *
  * @param int $code     (optional) error code
  *
  * @param int $mode     (optional) error mode, one of: oledrion_PEAR_ERROR_RETURN,
  * oledrion_PEAR_ERROR_PRINT, oledrion_PEAR_ERROR_DIE, oledrion_PEAR_ERROR_TRIGGER,
  * oledrion_PEAR_ERROR_CALLBACK or oledrion_PEAR_ERROR_EXCEPTION
  *
  * @param mixed $options   (optional) error level, _OR_ in the case of
  * oledrion_PEAR_ERROR_CALLBACK, the callback function or object/method
  * tuple.
  *
  * @param string $userinfo (optional) additional user/debug info
  *
  * @access public
  *
  */
 function __construct($message = 'unknown error', $code = null, $mode = null, $options = null, $userinfo = null)
 {
     if ($mode === null) {
         $mode = oledrion_PEAR_ERROR_RETURN;
     }
     $this->message = $message;
     $this->code = $code;
     $this->mode = $mode;
     $this->userinfo = $userinfo;
     if (!oledrion_PEAR::getStaticProperty('PEAR_Error', 'skiptrace')) {
         $this->backtrace = debug_backtrace();
         if (isset($this->backtrace[0]) && isset($this->backtrace[0]['object'])) {
             unset($this->backtrace[0]['object']);
         }
     }
     if ($mode & oledrion_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 & oledrion_PEAR_ERROR_PRINT) {
         if (is_null($options) || is_int($options)) {
             $format = "%s";
         } else {
             $format = $options;
         }
         printf($format, $this->getMessage());
     }
     if ($this->mode & oledrion_PEAR_ERROR_TRIGGER) {
         trigger_error($this->getMessage(), $this->level);
     }
     if ($this->mode & oledrion_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;
         }
         die(sprintf($format, $msg));
     }
     if ($this->mode & oledrion_PEAR_ERROR_CALLBACK) {
         if (is_callable($this->callback)) {
             call_user_func($this->callback, $this);
         }
     }
     if ($this->mode & oledrion_PEAR_ERROR_EXCEPTION) {
         trigger_error("oledrion_PEAR_ERROR_EXCEPTION is obsolete, use class PEAR_Exception for exceptions", E_USER_WARNING);
         eval('$e = new Exception($this->message, $this->code);throw($e);');
     }
 }
Example #2
0
 /**
  * Trigger a PEAR error
  *
  * To improve performances, the PEAR.php file is included dynamically.
  * The file is so included only when an error is triggered. So, in most
  * cases, the file isn't included and perfs are much better.
  *
  * @param string $msg error message
  * @param int $code error code
  * @access public
  */
 function raiseError($msg, $code)
 {
     include_once 'PEAR.php';
     return oledrion_PEAR::raiseError($msg, $code, $this->_pearErrorMode);
 }