diff options
author | xue <> | 2005-11-17 15:28:20 +0000 |
---|---|---|
committer | xue <> | 2005-11-17 15:28:20 +0000 |
commit | aa2edcf52ee7438876d826283274bf7e271fad4a (patch) | |
tree | 0028051b95e14fb09f52b993122910d2ef7a2fe8 /framework/Exceptions/TErrorHandler.php | |
parent | b4f41b167b62bb628d0809fc0e9438e11dce2bb5 (diff) |
Modified how errors are handled.
Diffstat (limited to 'framework/Exceptions/TErrorHandler.php')
-rw-r--r-- | framework/Exceptions/TErrorHandler.php | 62 |
1 files changed, 51 insertions, 11 deletions
diff --git a/framework/Exceptions/TErrorHandler.php b/framework/Exceptions/TErrorHandler.php index f88396ce..47feb54c 100644 --- a/framework/Exceptions/TErrorHandler.php +++ b/framework/Exceptions/TErrorHandler.php @@ -1,26 +1,23 @@ <?php
-class TErrorHandler extends TComponent implements IErrorHandler
+class TErrorHandler extends TComponent implements IModule
{
/**
* @var string module ID
*/
private $_id;
- /**
- * @var boolean whether the module is initialized
- */
- private $_initialized=false;
+ private $_application;
/**
* Initializes the module.
* This method is required by IModule and is invoked by application.
- * @param IApplication application
+ * @param TApplication application
* @param TXmlElement module configuration
*/
public function init($application,$config)
{
- $application->attachEventHandler('Error',array($this,'handle'));
- $this->_initialized=true;
+ $this->_application=$application;
+ $application->attachEventHandler('Error',array($this,'handleError'));
$application->setErrorHandler($this);
}
@@ -40,9 +37,52 @@ class TErrorHandler extends TComponent implements IErrorHandler $this->_id=$value;
}
- public function handle($sender,$param)
- { echo '...........................';
- echo $param;
+ public function handleError($sender,$param)
+ {
+ $type='Unhandled Exception';
+ $this->displayException($param,$type);
+ }
+
+ protected function displayException($exception,$type)
+ {
+ $lines=file($exception->getFile());
+ $errorLine=$exception->getLine();
+ $beginLine=$errorLine-9>=0?$errorLine-9:0;
+ $endLine=$errorLine+8<=count($lines)?$errorLine+8:count($lines);
+ $source='';
+ for($i=$beginLine;$i<$endLine;++$i)
+ {
+ if($i===$errorLine-1)
+ {
+ $line=highlight_string(sprintf("Line %4d: %s",$i+1,$lines[$i]),true);
+ $source.="<div style=\"background-color: #ffeeee\">".$line."</div>";
+ }
+ else
+ $source.=highlight_string(sprintf("Line %4d: %s",$i+1,$lines[$i]),true);
+ }
+ $fields=array(
+ '%%ErrorType%%',
+ '%%ErrorMessage%%',
+ '%%SourceFile%%',
+ '%%SourceCode%%',
+ '%%StackTrace%%',
+ '%%Version%%'
+ );
+ $values=array(
+ get_class($exception),
+ htmlspecialchars($exception->getMessage()),
+ htmlspecialchars($exception->getFile()).' ('.$exception->getLine().')',
+ $source,
+ htmlspecialchars($exception->getTraceAsString()),
+ $_SERVER['SERVER_SOFTWARE'].' <a href="http://www.pradosoft.com/">PRADO</a>/'.Prado::getVersion()
+ );
+ $languages=Prado::getUserLanguages();
+ $errorFile=dirname(__FILE__).'/error.'.$languages[0];
+ if(!is_file($errorFile))
+ $errorFile=dirname(__FILE__).'/error.en';
+ if(($content=@file_get_contents($errorFile))===false)
+ die("Unable to open error template file '$errorFile'.");
+ echo str_replace($fields,$values,$content);
}
}
|