summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2006-02-08 21:56:07 +0000
committerxue <>2006-02-08 21:56:07 +0000
commitb4103f28384d4ce9b5dc8e8a1abfda378eb42db0 (patch)
treecfe53b6c3d4aae7b56789fd4feaf03b3f426e9fb
parent1f19172f3df377ca0e88bb230d6f374ebef41b91 (diff)
Modified application lifecycles.
-rw-r--r--framework/TApplication.php98
-rw-r--r--framework/Web/Services/TPageService.php4
-rw-r--r--framework/Web/THttpResponse.php12
3 files changed, 66 insertions, 48 deletions
diff --git a/framework/TApplication.php b/framework/TApplication.php
index 151ff803..b85e3dcc 100644
--- a/framework/TApplication.php
+++ b/framework/TApplication.php
@@ -73,20 +73,21 @@ require_once(PRADO_DIR.'/Web/Services/TPageService.php');
* TApplication maintains a lifecycle with the following stages:
* - [construct] : construction of the application instance
* - [initApplication] : load application configuration and instantiate modules and the requested service
- * - BeginRequest : this event happens right after application initialization
- * - Authentication : this event happens when authentication is needed for the current request
- * - PostAuthentication : this event happens right after the authentication is done for the current request
- * - Authorization : this event happens when authorization is needed for the current request
- * - PostAuthorization : this event happens right after the authorization is done for the current request
- * - LoadState : this event happens when application state needs to be loaded
- * - PostLoadState : this event happens right after the application state is loaded
- * - PreRunService : this event happens right before the requested service is to run
- * - RunService : this event happens when the requested service runs
- * - PostRunService : this event happens right after the requested service finishes running
- * - SaveState : this event happens when application needs to save its state
- * - PostSaveState : this event happens right after the application saves its state
- * - EndRequest : this is the last stage a request is being completed
- * - ExitApplication : this is the last stage before application instance is destructed
+ * - onBeginRequest : this event happens right after application initialization
+ * - onAuthentication : this event happens when authentication is needed for the current request
+ * - onAuthenticationComplete : this event happens right after the authentication is done for the current request
+ * - onAuthorization : this event happens when authorization is needed for the current request
+ * - onAuthorizationComplete : this event happens right after the authorization is done for the current request
+ * - onLoadState : this event happens when application state needs to be loaded
+ * - onLoadStateComplete : this event happens right after the application state is loaded
+ * - onPreRunService : this event happens right before the requested service is to run
+ * - runService : the requested service runs
+ * - onSaveState : this event happens when application needs to save its state
+ * - onSaveStateComplete : this event happens right after the application saves its state
+ * - 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,
@@ -143,16 +144,17 @@ class TApplication extends TComponent
private static $_steps=array(
'onBeginRequest',
'onAuthentication',
- 'onPostAuthentication',
+ 'onAuthenticationComplete',
'onAuthorization',
- 'onPostAuthorization',
+ 'onAuthorizationComplete',
'onLoadState',
- 'onPostLoadState',
+ 'onLoadStateComplete',
'onPreRunService',
- 'onRunService',
- 'onPostRunService',
+ 'runService',
'onSaveState',
- 'onPostSaveState',
+ 'onSaveStateComplete',
+ 'onPreFlushOutput',
+ 'flushOutput',
'onEndRequest'
);
@@ -855,12 +857,12 @@ class TApplication extends TComponent
}
/**
- * Raises OnPostAuthentication event.
+ * Raises OnAuthenticationComplete event.
* This method is invoked right after the user request is authenticated.
*/
- public function onPostAuthentication()
+ public function onAuthenticationComplete()
{
- $this->raiseEvent('OnPostAuthentication',$this,null);
+ $this->raiseEvent('OnAuthenticationComplete',$this,null);
}
/**
@@ -873,12 +875,12 @@ class TApplication extends TComponent
}
/**
- * Raises OnPostAuthorization event.
+ * Raises OnAuthorizationComplete event.
* This method is invoked right after the user request is authorized.
*/
- public function onPostAuthorization()
+ public function onAuthorizationComplete()
{
- $this->raiseEvent('OnPostAuthorization',$this,null);
+ $this->raiseEvent('OnAuthorizationComplete',$this,null);
}
/**
@@ -892,12 +894,12 @@ class TApplication extends TComponent
}
/**
- * Raises OnPostLoadState event.
+ * Raises OnLoadStateComplete event.
* This method is invoked right after the application state has been loaded.
*/
- public function onPostLoadState()
+ public function onLoadStateComplete()
{
- $this->raiseEvent('OnPostLoadState',$this,null);
+ $this->raiseEvent('OnLoadStateComplete',$this,null);
}
/**
@@ -910,26 +912,15 @@ class TApplication extends TComponent
}
/**
- * Raises OnRunService event.
- * This method is invoked when the service runs.
+ * Runs the requested service.
*/
- public function onRunService()
+ public function runService()
{
- $this->raiseEvent('OnRunService',$this,null);
if($this->_service)
$this->_service->run();
}
/**
- * Raises OnPostRunService event.
- * This method is invoked right after the servie is run.
- */
- public function onPostRunService()
- {
- $this->raiseEvent('OnPostRunService',$this,null);
- }
-
- /**
* Raises OnSaveState event.
* This method is invoked when the application needs to save state (probably stored in session).
*/
@@ -940,12 +931,29 @@ class TApplication extends TComponent
}
/**
- * Raises OnPostSaveState event.
+ * Raises OnSaveStateComplete event.
* This method is invoked right after the application state has been saved.
*/
- public function onPostSaveState()
+ public function onSaveStateComplete()
+ {
+ $this->raiseEvent('OnSaveStateComplete',$this,null);
+ }
+
+ /**
+ * Raises OnPreFlushOutput event.
+ * This method is invoked right before the application flushes output to client.
+ */
+ public function onPreFlushOutput()
+ {
+ $this->raiseEvent('OnPreFlushOutput',$this,null);
+ }
+
+ /**
+ * Flushes output to client side.
+ */
+ public function flushOutput()
{
- $this->raiseEvent('OnPostSaveState',$this,null);
+ $this->getResponse()->flush();
}
/**
diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php
index 239cf870..463f2dec 100644
--- a/framework/Web/Services/TPageService.php
+++ b/framework/Web/Services/TPageService.php
@@ -455,9 +455,7 @@ class TPageService extends TService
else
throw new THttpException(404,'pageservice_page_unknown',$this->_pagePath);
- $writer=$this->getResponse()->createHtmlWriter();
- $this->_page->run($writer);
- $writer->flush();
+ $this->_page->run($this->getResponse()->createHtmlWriter());
}
/**
diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php
index 1cbf9751..d64a82af 100644
--- a/framework/Web/THttpResponse.php
+++ b/framework/Web/THttpResponse.php
@@ -297,6 +297,18 @@ class THttpResponse extends TModule implements ITextWriter
}
/**
+ * Returns the content in the output buffer.
+ * The buffer will NOT be cleared after calling this method.
+ * Use {@link clear()} is you want to clear the buffer.
+ * @return string output that is in the buffer.
+ */
+ public function getContents()
+ {
+ Prado::trace("Retrieving output",'System.Web.THttpResponse');
+ return $this->_bufferOutput?ob_get_contents():'';
+ }
+
+ /**
* Clears any existing buffered content.
*/
public function clear()