Example #1
0
 /**
  * 显示exception错误信息
  * @param LogicException $e 
  */
 function handler($e)
 {
     if ($e->getCode() == 404 && !DEBUG) {
         header("HTTP/1.0 404 Not Found");
         exit;
     }
     // 正式情况下
     $this->out['_msg'] = $e->getMessage();
     $this->out['_code'] = $e->getCode();
     // 只有LogicException才需要显示详细,记录日志
     if ($e instanceof LogicException) {
         // DEBUG时显示调试详细信息
         if (DEBUG) {
             $this->out['_exception_detail']['trace'] = $this->getTraceDesc($e->getTrace());
             $this->out['_exception_detail']['file'] = $e->getFile();
             $this->out['_exception_detail']['line'] = $e->getLine();
         } else {
             $this->out['_msg'] = '系统错误';
         }
     }
     if (!$this->tpl) {
         $this->tpl = PATH_APP . '/template/msg.tpl';
     }
     $this->display();
 }
Example #2
0
 /**
  * Magic method implementation of the above (for PHP >= 5.2.0), so we can do, eg:
  *     $foo = new Message( $key );
  *     $string = "<abbr>$foo</abbr>";
  *
  * @since 1.18
  *
  * @return string
  */
 public function __toString()
 {
     if ($this->format !== 'parse') {
         $ex = new LogicException(__METHOD__ . ' using implicit format: ' . $this->format);
         \MediaWiki\Logger\LoggerFactory::getInstance('message-format')->warning($ex->getMessage(), ['exception' => $ex, 'format' => $this->format, 'key' => $this->key]);
     }
     // PHP doesn't allow __toString to throw exceptions and will
     // trigger a fatal error if it does. So, catch any exceptions.
     try {
         return $this->toString();
     } catch (Exception $ex) {
         try {
             trigger_error("Exception caught in " . __METHOD__ . " (message " . $this->key . "): " . $ex, E_USER_WARNING);
         } catch (Exception $ex) {
             // Doh! Cause a fatal error after all?
         }
         if ($this->format === 'plain' || $this->format === 'text') {
             return '<' . $this->key . '>';
         }
         return '&lt;' . htmlspecialchars($this->key) . '&gt;';
     }
 }