From aa2edcf52ee7438876d826283274bf7e271fad4a Mon Sep 17 00:00:00 2001
From: xue <>
Date: Thu, 17 Nov 2005 15:28:20 +0000
Subject: Modified how errors are handled.
---
framework/Exceptions/TErrorHandler.php | 62 ++++++++++++++++++++++++++++------
framework/Exceptions/TException.php | 5 +--
framework/Exceptions/error.en | 34 +++++++++++++++++++
framework/Exceptions/messages.en | 16 +++++++++
4 files changed, 104 insertions(+), 13 deletions(-)
create mode 100644 framework/Exceptions/error.en
(limited to 'framework/Exceptions')
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 @@
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.="
".$line."
";
+ }
+ 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'].' PRADO/'.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 @@
+
+
+%%ErrorType%%
+
+
+
+
+%%ErrorType%%
+Description
+%%ErrorMessage%%
+
+
Source File
+%%SourceFile%%
+
+%%SourceCode%%
+
+Stack Trace
+
+%%Version%%
+
+
\ 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 uses an invalid file path "%s".
+appconfig_aliasid_required = Application configuration element must have an "id" attribute.
+appconfig_using_invalid = Application configuration element must have a "namespace" attribute.
+appconfig_moduleid_required = Application configuration element must have an "id" attribute.
+appconfig_moduletype_required = Application configuration must have a "type" attribute.
+appconfig_serviceid_required = Application configuration element must have an "id" attribute.
+appconfig_servicetype_required = Application configuration must have a "type" attribute.
+appconfig_parameterid_required = Application configuration 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'.
--
cgit v1.2.3