summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorxue <>2005-11-17 19:21:21 +0000
committerxue <>2005-11-17 19:21:21 +0000
commitd833d2766f28f927cb4e1e8e660771361abdfdf9 (patch)
treef64d674c8e1ce25bdb712efb64fdf5557db9e550 /framework
parentaa2edcf52ee7438876d826283274bf7e271fad4a (diff)
added application mode support.
Diffstat (limited to 'framework')
-rw-r--r--framework/Exceptions/TErrorHandler.php24
-rw-r--r--framework/Exceptions/error.en9
-rw-r--r--framework/TApplication.php20
-rw-r--r--framework/Web/Services/TPageService.php40
-rw-r--r--framework/Web/UI/TThemeManager.php17
5 files changed, 57 insertions, 53 deletions
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'].' <a href="http://www.pradosoft.com/">PRADO</a>/'.Prado::getVersion()
+ $_SERVER['SERVER_SOFTWARE'].' <a href="http://www.pradosoft.com/">PRADO</a>/'.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;}
</style>
</head>
@@ -16,7 +16,7 @@ code,pre {font-family:"Lucida Console";}
<body bgcolor="white">
<h1>%%ErrorType%%</h1>
<h3>Description</h3>
-<p>%%ErrorMessage%%</p>
+<p style="color:maroon">%%ErrorMessage%%</p>
<p>
<h3>Source File</h3>
<p>%%SourceFile%%</p>
@@ -29,6 +29,9 @@ code,pre {font-family:"Lucida Console";}
%%StackTrace%%
</pre></code>
</div>
-<div class="version">%%Version%%</div>
+<div class="version">
+%%Version%%<br/>
+%%Time%%
+</div>
</body>
</html> \ 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.
@@ -242,6 +246,22 @@ class TApplication extends TComponent
}
/**
+ * @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
*/
public function getConfigurationFile()
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
@@ -56,10 +56,6 @@ class TPageService extends TComponent implements IService
*/
private $_properties;
/**
- * @var integer cache expiration
- */
- private $_cacheExpire=-1;
- /**
* @var boolean whether service is initialized
*/
private $_initialized=false;
@@ -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()));
}
}
@@ -219,38 +215,6 @@ class TPageService extends TComponent implements IService
}
/**
- * @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
*/
public function getDefaultPage()
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;
}