From f6a77cd876890c71285574480d61f836bf204421 Mon Sep 17 00:00:00 2001 From: "haertl.mike" <> Date: Wed, 11 Feb 2009 15:24:27 +0000 Subject: Added caching of message files to TException --- HISTORY | 3 ++- framework/Exceptions/TException.php | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/HISTORY b/HISTORY index 1ac2e726..a95d080b 100644 --- a/HISTORY +++ b/HISTORY @@ -1,7 +1,8 @@ Version 3.1.5 (to be released) ============================== BUG: URL wildcard patterns didn't work with subfolders -BUG: Issue~107 - typo in TDbConnection::getCharset() (Christophe) +BUG: Issue#107 - typo in TDbConnection::getCharset() (Christophe) +ENH: Added caching of message files to TException (Michael) Version 3.1.4 January 11, 2009 ============================== diff --git a/framework/Exceptions/TException.php b/framework/Exceptions/TException.php index c6a87b4d..073b587d 100644 --- a/framework/Exceptions/TException.php +++ b/framework/Exceptions/TException.php @@ -35,6 +35,7 @@ class TException extends Exception { private $_errorCode=''; + static $_messageCache=array(); /** * Constructor. @@ -64,16 +65,20 @@ class TException extends Exception protected function translateErrorMessage($key) { $msgFile=$this->getErrorMessageFile(); - if(($entries=@file($msgFile))!==false) - { - foreach($entries as $entry) + + // Cache messages + if (!isset(self::$_messageCache[$msgFile])) + { + if(($entries=@file($msgFile))!==false) { - @list($code,$message)=explode('=',$entry,2); - if(trim($code)===$key) - return trim($message); + foreach($entries as $entry) + { + @list($code,$message)=explode('=',$entry,2); + self::$_messageCache[$msgFile][trim($code)]=trim($message); + } } - } - return $key; + } + return isset(self::$_messageCache[$msgFile][$key]) ? self::$_messageCache[$msgFile][$key] : $key; } /** -- cgit v1.2.3