[limb-svn] r6019 - 3.x/trunk/limb/web_app/src/filter
svn at limb-project.com
svn at limb-project.com
Wed Jun 27 18:29:40 MSD 2007
Author: serega
Date: 2007-06-27 18:29:40 +0400 (Wed, 27 Jun 2007)
New Revision: 6019
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6019
Modified:
3.x/trunk/limb/web_app/src/filter/lmbUncaughtExceptionHandlingFilter.class.php
Log:
-- lmbUncaughtExceptionHandlingFilter now accepts $error500_page parameter in constructor. Using this parameter you can pass the path to .html page with 500 error description. This should be an absolute path to static html page.
-- lmbUncaughtExceptionHandlingFilter also takes into account LIMB_APP_MODE constant to set it's mode. LIMB_APP_MODE constant should have 'devel' or 'production' value. On 'devel' mode all errors and uncaught exceptions will be displayed with backtrace but in 'production' mode - the contents of error500_page will be displayed instead.
Modified: 3.x/trunk/limb/web_app/src/filter/lmbUncaughtExceptionHandlingFilter.class.php
===================================================================
--- 3.x/trunk/limb/web_app/src/filter/lmbUncaughtExceptionHandlingFilter.class.php 2007-06-27 12:24:39 UTC (rev 6018)
+++ 3.x/trunk/limb/web_app/src/filter/lmbUncaughtExceptionHandlingFilter.class.php 2007-06-27 14:29:40 UTC (rev 6019)
@@ -1,25 +1,43 @@
<?php
-/*
- * Limb PHP Framework
- *
- * @link http://limb-project.com
- * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
- * @license LGPL http://www.gnu.org/copyleft/lesser.html
+/*
+ * Limb PHP Framework
+ *
+ * @link http://limb-project.com
+ * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com)
+ * @license LGPL http://www.gnu.org/copyleft/lesser.html
*/
lmb_require('limb/filter_chain/src/lmbInterceptingFilter.interface.php');
-lmb_require('limb/core/src/lmbErrorGuard.class.php');
-
+lmb_require('limb/core/src/lmbErrorGuard.class.php');
+
/**
* class lmbUncaughtExceptionHandlingFilter.
*
* @package web_app
* @version $Id$
- */
+ */
class lmbUncaughtExceptionHandlingFilter implements lmbInterceptingFilter
{
- const CONTEXT_RADIUS = 3;
+ const CONTEXT_RADIUS = 3;
+ const MODE_DEVEL = 'devel';
+ const MODE_PRODUCTION = 'production';
+
protected $toolkit;
+ protected $error_page;
+ protected $mode;
+ function __construct($error500_page = '')
+ {
+ if(!$error500_page)
+ $error500_page = dirname(__FILE__) . '/../../template/server_error.html';
+
+ $this->error_page = $error500_page;
+
+ if(!defined('LIMB_APP_MODE'))
+ $this->mode = self :: MODE_DEVEL;
+ else
+ $this->mode = LIMB_APP_MODE;
+ }
+
function run($filter_chain)
{
$this->toolkit = lmbToolkit :: instance();
@@ -35,6 +53,42 @@
$this->toolkit->getLog()->error($error['message']);
$this->toolkit->getResponse()->reset();
+ if($this->mode == self :: MODE_DEVEL)
+ $this->_echoErrorBacktrace($error);
+
+ if($this->mode == self :: MODE_PRODUCTION)
+ $this->_echoErrorPage();
+
+ exit(1);
+ }
+
+ function handleException($e)
+ {
+ if(function_exists('debugBreak'))
+ debugBreak();
+
+ $this->toolkit->getLog()->exception($e);
+ $this->toolkit->getResponse()->reset();
+
+ if($this->mode == self :: MODE_DEVEL)
+ $this->_echoExceptionBacktrace($e);
+
+ if($this->mode == self :: MODE_PRODUCTION)
+ $this->_echoErrorPage();
+
+ exit(1);
+ }
+
+ function _echoErrorPage()
+ {
+ for($i=0; $i < ob_get_level(); $i++)
+ ob_end_clean();
+
+ echo file_get_contents($this->error_page);
+ }
+
+ protected function _echoErrorBacktrace($error)
+ {
$message = $error['message'];
$trace = '';
$file = $error['file'];
@@ -47,17 +101,10 @@
$session = htmlspecialchars($this->toolkit->getSession()->dump());
echo $this->_renderTemplate($message, $trace, $file, $line, $context, $request, $session);
- exit(1);
}
- function handleException($e)
+ protected function _echoExceptionBacktrace($e)
{
- if(function_exists('debugBreak'))
- debugBreak();
-
- $this->toolkit->getLog()->exception($e);
- $this->toolkit->getResponse()->reset();
-
$error = htmlspecialchars($e->getMessage());
$trace = htmlspecialchars($e->getTraceAsString());
list($file, $line) = $this->_extractExceptionFileAndLine($e);
@@ -69,7 +116,6 @@
ob_end_clean();
echo $this->_renderTemplate($error, $trace, $file, $line, $context, $request, $session);
- exit(1);
}
protected function _renderTemplate($error, $trace, $file, $line, $context, $request, $session)
More information about the limb-svn
mailing list