From d833d2766f28f927cb4e1e8e660771361abdfdf9 Mon Sep 17 00:00:00 2001 From: xue <> Date: Thu, 17 Nov 2005 19:21:21 +0000 Subject: added application mode support. --- framework/Exceptions/TErrorHandler.php | 24 +++++++++++++++----- framework/Exceptions/error.en | 9 +++++--- framework/TApplication.php | 20 +++++++++++++++++ framework/Web/Services/TPageService.php | 40 ++------------------------------- framework/Web/UI/TThemeManager.php | 17 ++++++++------ 5 files changed, 57 insertions(+), 53 deletions(-) (limited to 'framework') diff --git a/framework/Exceptions/TErrorHandler.php b/framework/Exceptions/TErrorHandler.php index 47feb54c..af41e056 100644 --- a/framework/Exceptions/TErrorHandler.php +++ b/framework/Exceptions/TErrorHandler.php @@ -39,11 +39,23 @@ class TErrorHandler extends TComponent implements IModule public function handleError($sender,$param) { - $type='Unhandled Exception'; - $this->displayException($param,$type); + if(($response=Prado::getApplication()->getResponse())!==null) + $response->clear(); + switch(Prado::getApplication()->getMode()) + { + case 'Off': + case 'Debug': + $this->displayException($param); + exit(1); + case 'Normal': + case 'Performance': + error_log($param->__toString()); + header("HTTP/1.0 500 Internal Error"); + exit(1); + } } - protected function displayException($exception,$type) + protected function displayException($exception) { $lines=file($exception->getFile()); $errorLine=$exception->getLine(); @@ -66,7 +78,8 @@ class TErrorHandler extends TComponent implements IModule '%%SourceFile%%', '%%SourceCode%%', '%%StackTrace%%', - '%%Version%%' + '%%Version%%', + '%%Time%%' ); $values=array( get_class($exception), @@ -74,7 +87,8 @@ class TErrorHandler extends TComponent implements IModule htmlspecialchars($exception->getFile()).' ('.$exception->getLine().')', $source, htmlspecialchars($exception->getTraceAsString()), - $_SERVER['SERVER_SOFTWARE'].' PRADO/'.Prado::getVersion() + $_SERVER['SERVER_SOFTWARE'].' PRADO/'.Prado::getVersion(), + strftime('%Y-%m-%d %H:%m',time()) ); $languages=Prado::getUserLanguages(); $errorFile=dirname(__FILE__).'/error.'.$languages[0]; diff --git a/framework/Exceptions/error.en b/framework/Exceptions/error.en index 146ed2e8..1d76c7f2 100644 --- a/framework/Exceptions/error.en +++ b/framework/Exceptions/error.en @@ -8,7 +8,7 @@ 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;} +td,.version {color: gray;font-size:8pt;border-top:1px solid #aaaaaa;} .source {font-family:"Lucida Console";font-weight:normal;background-color:#ffffee;} @@ -16,7 +16,7 @@ code,pre {font-family:"Lucida Console";}

%%ErrorType%%

Description

-

%%ErrorMessage%%

+

%%ErrorMessage%%

Source File

%%SourceFile%%

@@ -29,6 +29,9 @@ code,pre {font-family:"Lucida Console";} %%StackTrace%% -
%%Version%%
+
+%%Version%%
+%%Time%% +
\ No newline at end of file diff --git a/framework/TApplication.php b/framework/TApplication.php index 5b52fd22..9ac9a8a0 100644 --- a/framework/TApplication.php +++ b/framework/TApplication.php @@ -157,6 +157,10 @@ class TApplication extends TComponent * @var TAuthorizationRuleCollection collection of authorization rules */ private $_authRules=null; + /** + * @var string application mode + */ + private $_mode='Debug'; /** * Constructor. @@ -241,6 +245,22 @@ class TApplication extends TComponent return $this->_uniqueID; } + /** + * @return string application mode (Off|Debug|Normal|Peformance), defaults to Debug. + */ + public function getMode() + { + return $this->_mode; + } + + /** + * @param string application mode. Valid values include Off, Debug, Normal, or Peformance + */ + public function setMode($value) + { + $this->_mode=TPropertyValue::ensureEnum($value,array('Off','Debug','Normal','Performance')); + } + /** * @return string configuration file path */ diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php index 6c690046..bc921c0e 100644 --- a/framework/Web/Services/TPageService.php +++ b/framework/Web/Services/TPageService.php @@ -55,10 +55,6 @@ class TPageService extends TComponent implements IService * @var array list of initial page property values */ private $_properties; - /** - * @var integer cache expiration - */ - private $_cacheExpire=-1; /** * @var boolean whether service is initialized */ @@ -100,7 +96,7 @@ class TPageService extends TComponent implements IService if(is_array($arr)) { list($pageConfig,$timestamp)=$arr; - if($this->_cacheExpire<0) + if($application->getMode()!=='Performance') { // check to see if cache is the latest $paths=explode('.',$this->_pagePath); @@ -126,7 +122,7 @@ class TPageService extends TComponent implements IService $pageConfig=new TPageConfiguration; $pageConfig->loadXmlElement($config,dirname($application->getConfigurationFile()),null); $pageConfig->loadConfigurationFiles($this->_pagePath,$basePath); - $cache->set(self::CONFIG_CACHE_PREFIX.$this->_pagePath,array($pageConfig,time()),$this->_cacheExpire<0?0:$this->_cacheExpire); + $cache->set(self::CONFIG_CACHE_PREFIX.$this->_pagePath,array($pageConfig,time())); } } @@ -218,38 +214,6 @@ class TPageService extends TComponent implements IService return $this->_pagePath===$pagePath; } - /** - * @return integer the expiration time of the configuration saved in cache, - * -1 (default) ensures the cached configuration always catches up the latest configuration files, - * 0 means never expire, - * a number less or equal than 60*60*24*30 means the number of seconds that the value will remain valid. - * a number greater than 60 means a UNIX timestamp after which the value will expire. - */ - public function getCacheExpire() - { - return $this->_cacheExpire; - } - - /** - * Sets the expiration time of the configuration saved in cache. - * TPageService will try to use cache to save parsed configuration files. - * CacheExpire is used to control the caching policy. - * If you have changed this property, make sure to clean up cache first. - * @param integer the expiration time of the configuration saved in cache, - * -1 (default) ensures the cached configuration always catches up the latest configuration files, - * 0 means never expire, - * a number less or equal than 60*60*24*30 means the number of seconds that the value will remain valid. - * a number greater than 60 means a UNIX timestamp after which the value will expire. - * @throws TInvalidOperationException if the service is already initialized - */ - public function setCacheExpire($value) - { - if($this->_initialized) - throw new TInvalidOperationException('pageservice_cacheexpire_unchangeable'); - else - $this->_cacheExpire=TPropertyValue::ensureInteger($value); - } - /** * @return string default page path to be served if no explicit page is request */ diff --git a/framework/Web/UI/TThemeManager.php b/framework/Web/UI/TThemeManager.php index 5f347e8f..9b407b90 100644 --- a/framework/Web/UI/TThemeManager.php +++ b/framework/Web/UI/TThemeManager.php @@ -64,17 +64,20 @@ class TThemeManager extends TComponent implements IModule { list($theme,$timestamp)=$array; $cacheValid=true; - if(($dir=opendir($themePath))===false) - throw new TIOException('thememanager_themepath_invalid',$themePath); - while(($file=readdir($dir))!==false) + if($this->_application->getMode()!=='Performance') { - if(basename($file,'.skin')!==$file && filemtime($themePath.'/'.$file)>$timestamp) + if(($dir=opendir($themePath))===false) + throw new TIOException('thememanager_themepath_invalid',$themePath); + while(($file=readdir($dir))!==false) { - $cacheValid=false; - break; + if(basename($file,'.skin')!==$file && filemtime($themePath.'/'.$file)>$timestamp) + { + $cacheValid=false; + break; + } } + closedir($dir); } - closedir($dir); if($cacheValid) return $theme; } -- cgit v1.2.3