summaryrefslogtreecommitdiff
path: root/framework/Exceptions
diff options
context:
space:
mode:
authorxue <>2005-11-17 15:28:20 +0000
committerxue <>2005-11-17 15:28:20 +0000
commitaa2edcf52ee7438876d826283274bf7e271fad4a (patch)
tree0028051b95e14fb09f52b993122910d2ef7a2fe8 /framework/Exceptions
parentb4f41b167b62bb628d0809fc0e9438e11dce2bb5 (diff)
Modified how errors are handled.
Diffstat (limited to 'framework/Exceptions')
-rw-r--r--framework/Exceptions/TErrorHandler.php62
-rw-r--r--framework/Exceptions/TException.php5
-rw-r--r--framework/Exceptions/error.en34
-rw-r--r--framework/Exceptions/messages.en16
4 files changed, 104 insertions, 13 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);
}
}
diff --git a/framework/Exceptions/TException.php b/framework/Exceptions/TException.php
index 0c51e1f1..0bc963f8 100644
--- a/framework/Exceptions/TException.php
+++ b/framework/Exceptions/TException.php
@@ -51,8 +51,9 @@ class TException extends Exception
protected function translateErrorCode($key)
{
- // $msgFile=dirname(__FILE__).'/messages.'.Prado::getLocale();
- // if(!is_file($msgFile))
+ $languages=Prado::getUserLanguages();
+ $msgFile=dirname(__FILE__).'/messages.'.$languages[0];
+ if(!is_file($msgFile))
$msgFile=dirname(__FILE__).'/messages.en';
if(($entries=@file($msgFile))===false)
return $key;
diff --git a/framework/Exceptions/error.en b/framework/Exceptions/error.en
new file mode 100644
index 00000000..146ed2e8
--- /dev/null
+++ b/framework/Exceptions/error.en
@@ -0,0 +1,34 @@
+<html>
+<head>
+<title>%%ErrorType%%</title>
+<style>
+body {font-family:"Verdana";font-weight:normal;color:black;}
+h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
+h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
+h3 {font-family:"Verdana";font-weight:bold;font-size:11pt}
+p {font-family:"Verdana";font-weight:normal;color:black;font-size:9pt;margin-top: -5px}
+code,pre {font-family:"Lucida Console";}
+.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;}
+.source {font-family:"Lucida Console";font-weight:normal;background-color:#ffffee;}
+</style>
+</head>
+
+<body bgcolor="white">
+<h1>%%ErrorType%%</h1>
+<h3>Description</h3>
+<p>%%ErrorMessage%%</p>
+<p>
+<h3>Source File</h3>
+<p>%%SourceFile%%</p>
+<div class="source">
+%%SourceCode%%
+</div>
+<h3>Stack Trace</h3>
+<div class="source">
+<code><pre>
+%%StackTrace%%
+</pre></code>
+</div>
+<div class="version">%%Version%%</div>
+</body>
+</html> \ No newline at end of file
diff --git a/framework/Exceptions/messages.en b/framework/Exceptions/messages.en
index d949d88a..f1f6c9ad 100644
--- a/framework/Exceptions/messages.en
+++ b/framework/Exceptions/messages.en
@@ -1,3 +1,19 @@
+component_property_undefined = Component property '%s.%s' is not defined.
+
+application_configfile_inexistent = Application configuration file "%s" does not exist.
+application_module_existing = Application module "%s" cannot be registered twice.
+application_service_invalid = Service "%s" must implement IService interface.
+application_service_unknown = Requested service "%s" is not defined.
+
+appconfig_aliaspath_invalid = Application configuration <alias id="%s"> uses an invalid file path "%s".
+appconfig_aliasid_required = Application configuration <alias> element must have an "id" attribute.
+appconfig_using_invalid = Application configuration <using> element must have a "namespace" attribute.
+appconfig_moduleid_required = Application configuration <module> element must have an "id" attribute.
+appconfig_moduletype_required = Application configuration <module id="%s"> must have a "type" attribute.
+appconfig_serviceid_required = Application configuration <service> element must have an "id" attribute.
+appconfig_servicetype_required = Application configuration <service id="%s"> must have a "type" attribute.
+appconfig_parameterid_required = Application configuration <parameter> element must have an "id" attribute.
+
body_contents_not_allowed = %s: body contents are not allowed.
control_id_not_unique = Control ID '%s' is not unique for control type '%s'.
control_not_found = Unable to find a control with ID '%s'.