Source for file ErrorHandler.php

Documentation is available at ErrorHandler.php

  1. <?php
  2. /**
  3.  * Teeple2 - PHP5 Web Application Framework inspired by Seasar2
  4.  *
  5.  * PHP versions 5
  6.  *
  7.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  8.  * that is available through the world-wide-web at the following URI:
  9.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  10.  * the PHP License and are unable to obtain it through the web, please
  11.  * send a note to license@php.net so we can mail you a copy immediately.
  12.  *
  13.  * @package     teeple
  14.  * @author      Mitsutaka Sato <miztaka@gmail.com>
  15.  * @license     http://www.php.net/license/3_0.txt  PHP License 3.0
  16.  */
  17.  
  18. /**
  19.  * エラーハンドラークラスです。
  20.  * 
  21.  * @package teeple
  22.  */
  23. {
  24.     /**
  25.      * エラーハンドリングを行ないます。
  26.      * 
  27.      * @param Exception $e 例外クラス
  28.      */
  29.     public static function handle($e{
  30.  
  31.         // ロギング
  32.         self::handleLogging($e);
  33.  
  34.         // エラーページを出力
  35.         $display $e->getMessage();
  36.         $template 'common/exception.html';
  37.         
  38.         $renderer Teeple_Smarty4Maple::getInstance();
  39.         $renderer->assign('display'$display);
  40.         $renderer->assign('stack'$e->__toString());
  41.         $result $renderer->fetch($template);
  42.         if ($result == ""{
  43.             self::print_error($display);
  44.         }
  45.         print $result;
  46.         
  47.         return;
  48.     }
  49.     
  50.     /**
  51.      * ちょっと危険なので使わない。
  52.      *
  53.      * @param unknown_type $errno 
  54.      * @param unknown_type $errmsg 
  55.      * @param unknown_type $filename 
  56.      * @param unknown_type $linenum 
  57.      * @param unknown_type $vars 
  58.      */
  59.     /*
  60.     public static function handlePHPError($errno, $errmsg, $filename, $linenum, $vars) {
  61.  
  62.         // エラー番号 => 文字列
  63.         $errtype = array(
  64.             E_ERROR => 'E_ERROR',
  65.             E_PARSE => 'E_PARSE',
  66.             E_CORE_ERROR => 'E_CORE_ERROR',
  67.             E_CORE_WARNING => 'E_CORE_WARNING',  
  68.             E_COMPILE_ERROR => 'E_COMPILE_ERROR',
  69.             E_USER_ERROR => 'E_USER_ERROR',
  70.             E_USER_WARNING => 'E_USER_WARNING',
  71.             E_STRICT => 'E_STRICT',
  72.             E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR', 
  73.             E_WARNING => 'E_WARNING',
  74.             E_NOTICE => 'E_NOTICE',
  75.             E_COMPILE_WARNING => 'E_COMPILE_WARNING',
  76.             E_USER_NOTICE => 'E_USER_NOTICE'
  77.         );        
  78.         
  79.         // ロギング (エラー種別にあわせてレベルを代える。)
  80.         $level = NULL;
  81.         switch ($errno) {
  82.             case E_ERROR:
  83.             case E_PARSE:
  84.             case E_CORE_ERROR:                
  85.             case E_CORE_WARNING:  
  86.             case E_COMPILE_ERROR:
  87.             case E_USER_ERROR:
  88.             case E_USER_WARNING:
  89.             case E_RECOVERABLE_ERROR:
  90.                 $level = 'fatal';
  91.                 break;
  92.             case E_WARNING:
  93.             case E_NOTICE:
  94.             case E_COMPILE_WARNING:
  95.             case E_USER_NOTICE:
  96.                 $level = 'warn';
  97.                 break;
  98.             case E_STRICT:
  99.             default:
  100.                 break;
  101.         }
  102.         
  103.         if ($level != NULL) {
  104.             $log =& LoggerManager::getLogger(get_class($this));
  105.             $log->$level("[PHPError]errno={$errtype[$errno]},errmsg={$errmsg},filename={$filename},linenum={$linenum},vars=". var_export($vars, TRUE));
  106.  
  107.             // fatalの場合はエラー画面表示する
  108.             if ($level == 'fatal') {
  109.                 self::handle(new Teeple_Exception(MC::getLog(MSG_MA999), MSG_MA999));
  110.             }
  111.         }        
  112.         
  113.     }
  114.     */
  115.     
  116.     /**
  117.      * 例外のロギングを行ないます。
  118.      *
  119.      * @param Exception $e 例外クラス。
  120.      * 
  121.      */
  122.     public static function handleLogging($e{
  123.         
  124.         $log LoggerManager::getLogger('ErrorHandler');
  125.         
  126.         // メッセージとStackTraceをerrorでロギング
  127.         $log->fatal($e->getMessage());
  128.         $log->fatal("*** stack trace ***\n"$e->__toString());
  129.         $log->fatal("*** request dump ***\n"var_export(@$_REQUESTTRUE));
  130.         $log->fatal("*** session dump ***\n"var_export(@$_SESSIONTRUE));
  131.     }
  132.     
  133.     private static function print_error($display{
  134. ?><HTML>
  135. <BODY>
  136. <h3>エラーが発生しました。</h3>
  137. <p><?php echo $display ?></p>
  138. </BODY>
  139. <?php
  140.  
  141.         exit;
  142.     }
  143.     
  144. }
  145.  
  146. ?>

Documentation generated on Mon, 26 Apr 2010 08:59:44 +0900 by phpDocumentor 1.4.3