From 682d48577ae6e0118a11e5e6134fdbbb6048456d Mon Sep 17 00:00:00 2001 From: xue <> Date: Wed, 8 Feb 2006 22:33:11 +0000 Subject: Updated application lifecycle and related tutorial description. --- .../protected/pages/Fundamentals/applifecycles.gif | Bin 34714 -> 31200 bytes .../protected/pages/Fundamentals/applifecycles.vsd | Bin 216576 -> 220672 bytes framework/Log/TLogRouter.php | 2 +- framework/TApplication.php | 35 +++++++++------------ framework/Web/THttpResponse.php | 3 +- 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/demos/quickstart/protected/pages/Fundamentals/applifecycles.gif b/demos/quickstart/protected/pages/Fundamentals/applifecycles.gif index e4fc306c..d5300aa6 100644 Binary files a/demos/quickstart/protected/pages/Fundamentals/applifecycles.gif and b/demos/quickstart/protected/pages/Fundamentals/applifecycles.gif differ diff --git a/demos/quickstart/protected/pages/Fundamentals/applifecycles.vsd b/demos/quickstart/protected/pages/Fundamentals/applifecycles.vsd index 0f0e2bab..56f6602d 100644 Binary files a/demos/quickstart/protected/pages/Fundamentals/applifecycles.vsd and b/demos/quickstart/protected/pages/Fundamentals/applifecycles.vsd differ diff --git a/framework/Log/TLogRouter.php b/framework/Log/TLogRouter.php index 06877f0f..5326b598 100644 --- a/framework/Log/TLogRouter.php +++ b/framework/Log/TLogRouter.php @@ -68,7 +68,7 @@ class TLogRouter extends TModule throw new TConfigurationException('logrouter_configfile_invalid',$this->_configFile); } $this->loadConfig($config); - $this->getApplication()->attachEventHandler('OnExitApplication',array($this,'collectLogs')); + $this->getApplication()->attachEventHandler('OnEndRequest',array($this,'collectLogs')); } /** diff --git a/framework/TApplication.php b/framework/TApplication.php index b85e3dcc..1a982488 100644 --- a/framework/TApplication.php +++ b/framework/TApplication.php @@ -87,7 +87,6 @@ require_once(PRADO_DIR.'/Web/Services/TPageService.php'); * - onPreFlushOutput : this event happens right before the application flushes output to client side. * - flushOutput : the application flushes output to client side. * - onEndRequest : this is the last stage a request is being completed - * - onExitApplication : this is the last stage before application instance is destructed * - [destruct] : destruction of the application instance * Modules and services can attach their methods to one or several of the above * events and do appropriate processing when the events are raised. By this way, @@ -154,8 +153,7 @@ class TApplication extends TComponent 'onSaveState', 'onSaveStateComplete', 'onPreFlushOutput', - 'flushOutput', - 'onEndRequest' + 'flushOutput' ); /** @@ -333,20 +331,19 @@ class TApplication extends TComponent { if($this->_mode===self::STATE_OFF) throw new THttpException(503,'application_service_unavailable'); + if($this->_requestCompleted) + break; $method=self::$_steps[$this->_step]; - Prado::trace("Executing $method",'System.TApplication'); + Prado::trace("Executing $method()",'System.TApplication'); $this->$method(); - if($this->_requestCompleted && $this->_step<$n-1) - $this->_step=$n-1; - else - $this->_step++; + $this->_step++; } } catch(Exception $e) { $this->onError($e); } - $this->onExitApplication(); + $this->onEndRequest(); } /** @@ -359,6 +356,14 @@ class TApplication extends TComponent $this->_requestCompleted=true; } + /** + * @return boolean whether the current request is processed. + */ + public function getRequestCompleted() + { + return $this->_requestCompleted; + } + /** * Returns a global value. * @@ -831,8 +836,8 @@ class TApplication extends TComponent public function onError($param) { Prado::log($param->getMessage(),TLogger::ERROR,'System.TApplication'); - $this->getErrorHandler()->handleError($this,$param); $this->raiseEvent('OnError',$this,$param); + $this->getErrorHandler()->handleError($this,$param); } /** @@ -964,16 +969,6 @@ class TApplication extends TComponent { $this->raiseEvent('OnEndRequest',$this,null); } - - /** - * Raises OnExitApplication event. - * This method is invoked when the application instance is being destructed. - * Do not raise exceptions within this method or in the event handler. - */ - public function onExitApplication() - { - $this->raiseEvent('OnExitApplication',$this,null); - } } diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php index d64a82af..a8c3777a 100644 --- a/framework/Web/THttpResponse.php +++ b/framework/Web/THttpResponse.php @@ -265,7 +265,8 @@ class THttpResponse extends TModule implements ITextWriter */ public function redirect($url) { - $this->getApplication()->onExitApplication(); + if(!$this->getApplication()->getRequestCompleted()) + $this->getApplication()->onEndRequest(); header('Location:'.$url); exit(); } -- cgit v1.2.3