summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjavalizard <>2010-04-13 01:51:37 +0000
committerjavalizard <>2010-04-13 01:51:37 +0000
commitcdf641854fcf1f462c27f5422f86d08019fafb77 (patch)
tree3ba4257039b7f548df2b4a2b0676dff53ff7b8d6
parentcb8377b3025aebb6c0df5b62966377be298b2fec (diff)
Added TPage events to TPageService via an interface. When the page is run the TPageServices events are added to the TPage events. This exposes the TPage events to modules. Also added an event when a page is not found.
-rw-r--r--framework/Web/Services/TPageService.php151
-rw-r--r--framework/Web/UI/TPage.php96
2 files changed, 223 insertions, 24 deletions
diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php
index f36d10cd..43f5a3fd 100644
--- a/framework/Web/Services/TPageService.php
+++ b/framework/Web/Services/TPageService.php
@@ -68,13 +68,18 @@ Prado::using('System.Web.UI.TThemeManager');
* The first matching rule will be used. The last rule always allows all users
* accessing to any resources.
*
+ * The TPageService replicates the {@link TPage} events through {@link IPageEvents}.
+ * When the TPage is run, the TPageService events attach to all the corresponding TPage
+ * events. This allows modules to handle page events.
+ *
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Carl G. Mathisen <carlgmathisen@gmail.com>
+ * @author Brad Anderson <javalizard@gmail.com>
* @version $Id$
* @package System.Web.Services
* @since 3.0
*/
-class TPageService extends TService
+class TPageService extends TService implements IPageEvents
{
/**
* Configuration file name
@@ -137,7 +142,15 @@ class TPageService extends TService
* @var TTemplateManager template manager
*/
private $_templateManager=null;
-
+ /**
+ * @var TPage is set when traversing the event onNoPage
+ */
+ private $_foundpage = false;
+ /**
+ * @var boolean if the onNoPage event is specifically blocked
+ */
+ private $_blockOnNoPage = false;
+
/**
* Initializes the service.
* This method is required by IService interface and is invoked by application.
@@ -384,6 +397,35 @@ class TPageService extends TService
{
return $this->constructUrl($this->getDefaultPage());
}
+
+ /**
+ * This event is triggered when a 404 in the normal page tree hierarchy is not found
+ */
+ public function onNoPage($sender, $param) {
+ }
+
+
+ /**
+ * @return TPage This is used by the other modules to provide their pages. If they find one on an onNoPage event this is where it goes
+ */
+ public function getFoundPage() { return $this->_foundpage; }
+
+ /**
+ * This is set when a module finds a suitable page, this is set with that found page
+ * @param TPage the page to display
+ */
+ public function setFoundPage($v) { $this->_foundpage = $v; }
+
+ /**
+ * @return TPage This is used by the other modules to provide their pages. If they find one on an onNoPage event this is where it goes
+ */
+ public function getBlockOnNoPageEvent() { return $this->_blockOnNoPage; }
+
+ /**
+ * This is set when a module finds a suitable page, this is set with that found page
+ * @param TPage the page to display
+ */
+ public function setBlockOnNoPageEvent($v) { $this->_blockOnNoPage = TPropertyValue::ensureBoolean($v); }
/**
* @return string the root directory for storing pages. Defaults to the 'pages' directory under the application base path.
@@ -469,14 +511,19 @@ class TPageService extends TService
* @throws THttpException if requested page path is invalid
* @throws TConfigurationException if the page class cannot be found
*/
- protected function createPage($pagePath)
+ protected function createPage($pagePath, $doError = null)
{
$path=$this->getBasePath().DIRECTORY_SEPARATOR.strtr($pagePath,'.',DIRECTORY_SEPARATOR);
$hasTemplateFile=is_file($path.self::PAGE_FILE_EXT);
$hasClassFile=is_file($path.Prado::CLASS_FILE_EXT);
- if(!$hasTemplateFile && !$hasClassFile)
- throw new THttpException(404,'pageservice_page_unknown',$pagePath);
+ if(!$hasTemplateFile && !$hasClassFile && ($doError || $doError === null)) {
+ if(!$this->BlockOnNoPageEvent)
+ $this->raiseEvent('onNoPage', $this, $pagePath);
+ if(!$this->FoundPage)
+ throw new THttpException(404,'pageservice_page_unknown',$pagePath);
+ return $this->FoundPage;
+ }
if($hasClassFile)
{
@@ -513,6 +560,19 @@ class TPageService extends TService
{
foreach($properties as $name=>$value)
$page->setSubProperty($name,$value);
+
+ $page->OnDataBinding[] = array($this, 'OnDataBinding');
+ $page->OnPreInit[] = array($this, 'OnPreInit');
+ $page->OnInit[] = array($this, 'OnInit');
+ $page->OnInitComplete[] = array($this, 'OnInitComplete');
+ $page->OnPreLoad[] = array($this, 'OnPreLoad');
+ $page->OnLoad[] = array($this, 'OnLoad');
+ $page->OnLoadComplete[] = array($this, 'OnLoadComplete');
+ $page->OnPreRender[] = array($this, 'OnPreRender');
+ $page->OnPreRenderComplete[] = array($this, 'OnPreRenderComplete');
+ $page->OnSaveStateComplete[] = array($this, 'OnSaveStateComplete');
+ $page->OnUnload[] = array($this, 'OnUnload');
+
$page->run($this->getResponse()->createHtmlWriter());
}
@@ -528,6 +588,87 @@ class TPageService extends TService
{
return $this->getRequest()->constructUrl($this->getID(),$pagePath,$getParams,$encodeAmpersand,$encodeGetItems);
}
+
+
+ /**
+ * Raises 'OnDataBinding' event. (inherited from TControl)
+ */
+ public function onDataBinding($param) {
+ Prado::trace("onDataBinding",'System.Web.Services.TPageService');
+ $this->raiseEvent('OnDataBinding',$this,$param);
+ }
+ /**
+ * This method is invoked when the control enters 'OnInit' stage. (inherited from TControl)
+ */
+ public function onInit($param) {
+ Prado::trace("onInit",'System.Web.Services.TPageService');
+ $this->raiseEvent('OnInit',$this,$param);
+ }
+ /**
+ * Raises OnInitComplete event.
+ */
+ public function onInitComplete($param) {
+ Prado::trace("onInitComplete",'System.Web.Services.TPageService');
+ $this->raiseEvent('OnInitComplete',$this,$param);
+ }
+ /**
+ * This method is invoked when the control enters 'OnLoad' stage. (inherited from TControl)
+ */
+ public function onLoad($param) {
+ Prado::trace("OnLoad",'System.Web.Services.TPageService');
+ $this->raiseEvent('OnLoad',$this,$param);
+ }
+ /**
+ * Raises OnLoadComplete event.
+ */
+ public function onLoadComplete($param) {
+ Prado::trace("OnLoadComplete",'System.Web.Services.TPageService');
+ $this->raiseEvent('OnLoadComplete',$this,$param);
+ }
+ /**
+ * Raises OnPreInit event.
+ */
+ public function onPreInit($param) {
+ Prado::trace("OnPreInit",'System.Web.Services.TPageService');
+ $this->raiseEvent('OnPreInit',$this,$param);
+ }
+ /**
+ * Raises OnPreLoad event.
+ */
+ public function onPreLoad($param) {
+ Prado::trace("OnPreLoad",'System.Web.Services.TPageService');
+ $this->raiseEvent('OnPreLoad',$this,$param);
+ }
+ /**
+ * This method is invoked when the control enters 'OnPreRender' stage. (inherited from TControl)
+ */
+ public function onPreRender($param) {
+ Prado::trace("OnPreRender",'System.Web.Services.TPageService');
+ $this->raiseEvent('OnPreRender',$this,$param);
+ }
+ /**
+ * Raises OnPreRenderComplete event.
+ */
+ public function onPreRenderComplete($param) {
+ Prado::trace("OnPreRenderComplete",'System.Web.Services.TPageService');
+ $this->raiseEvent('OnPreRenderComplete',$this,$param);
+ }
+ /**
+ * Raises OnSaveStateComplete event.
+ */
+ public function onSaveStateComplete($param) {
+ Prado::trace("OnSaveStateComplete",'System.Web.Services.TPageService');
+ $this->raiseEvent('OnSaveStateComplete',$this,$param);
+ }
+ /**
+ * This method is invoked when the control enters 'OnUnload' stage. (inherited from TControl)
+ */
+ public function onUnload($param) {
+ Prado::trace("OnUnload",'System.Web.Services.TPageService');
+ $this->raiseEvent('OnUnload',$this,$param);
+ }
+
+
}
diff --git a/framework/Web/UI/TPage.php b/framework/Web/UI/TPage.php
index 4a2ea474..3826499a 100644
--- a/framework/Web/UI/TPage.php
+++ b/framework/Web/UI/TPage.php
@@ -26,7 +26,7 @@ Prado::using('System.Web.UI.TClientScriptManager');
* @package System.Web.UI
* @since 3.0
*/
-class TPage extends TTemplateControl
+class TPage extends TTemplateControl implements IPageEvents
{
/**
* system post fields
@@ -201,30 +201,30 @@ class TPage extends TTemplateControl
protected function processNormalRequest($writer)
{
Prado::trace("Page onPreInit()",'System.Web.UI.TPage');
- $this->onPreInit(null);
+ $this->onPreInit($this);
Prado::trace("Page initRecursive()",'System.Web.UI.TPage');
$this->initRecursive();
Prado::trace("Page onInitComplete()",'System.Web.UI.TPage');
- $this->onInitComplete(null);
+ $this->onInitComplete($this);
Prado::trace("Page onPreLoad()",'System.Web.UI.TPage');
- $this->onPreLoad(null);
+ $this->onPreLoad($this);
Prado::trace("Page loadRecursive()",'System.Web.UI.TPage');
$this->loadRecursive();
Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage');
- $this->onLoadComplete(null);
+ $this->onLoadComplete($this);
Prado::trace("Page preRenderRecursive()",'System.Web.UI.TPage');
$this->preRenderRecursive();
Prado::trace("Page onPreRenderComplete()",'System.Web.UI.TPage');
- $this->onPreRenderComplete(null);
+ $this->onPreRenderComplete($this);
Prado::trace("Page savePageState()",'System.Web.UI.TPage');
$this->savePageState();
Prado::trace("Page onSaveStateComplete()",'System.Web.UI.TPage');
- $this->onSaveStateComplete(null);
+ $this->onSaveStateComplete($this);
Prado::trace("Page renderControl()",'System.Web.UI.TPage');
$this->renderControl($writer);
@@ -235,13 +235,13 @@ class TPage extends TTemplateControl
protected function processPostBackRequest($writer)
{
Prado::trace("Page onPreInit()",'System.Web.UI.TPage');
- $this->onPreInit(null);
+ $this->onPreInit($this);
Prado::trace("Page initRecursive()",'System.Web.UI.TPage');
$this->initRecursive();
Prado::trace("Page onInitComplete()",'System.Web.UI.TPage');
- $this->onInitComplete(null);
+ $this->onInitComplete($this);
$this->_restPostData=new TMap;
Prado::trace("Page loadPageState()",'System.Web.UI.TPage');
@@ -249,7 +249,7 @@ class TPage extends TTemplateControl
Prado::trace("Page processPostData()",'System.Web.UI.TPage');
$this->processPostData($this->_postData,true);
Prado::trace("Page onPreLoad()",'System.Web.UI.TPage');
- $this->onPreLoad(null);
+ $this->onPreLoad($this);
Prado::trace("Page loadRecursive()",'System.Web.UI.TPage');
$this->loadRecursive();
Prado::trace("Page processPostData()",'System.Web.UI.TPage');
@@ -259,17 +259,17 @@ class TPage extends TTemplateControl
Prado::trace("Page raisePostBackEvent()",'System.Web.UI.TPage');
$this->raisePostBackEvent();
Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage');
- $this->onLoadComplete(null);
+ $this->onLoadComplete($this);
Prado::trace("Page preRenderRecursive()",'System.Web.UI.TPage');
$this->preRenderRecursive();
Prado::trace("Page onPreRenderComplete()",'System.Web.UI.TPage');
- $this->onPreRenderComplete(null);
+ $this->onPreRenderComplete($this);
Prado::trace("Page savePageState()",'System.Web.UI.TPage');
$this->savePageState();
Prado::trace("Page onSaveStateComplete()",'System.Web.UI.TPage');
- $this->onSaveStateComplete(null);
+ $this->onSaveStateComplete($this);
Prado::trace("Page renderControl()",'System.Web.UI.TPage');
$this->renderControl($writer);
@@ -294,13 +294,13 @@ class TPage extends TTemplateControl
$this->_postData[$k]=iconv('UTF-8',$enc.'//IGNORE',$v);
Prado::trace("Page onPreInit()",'System.Web.UI.TPage');
- $this->onPreInit(null);
+ $this->onPreInit($this);
Prado::trace("Page initRecursive()",'System.Web.UI.TPage');
$this->initRecursive();
Prado::trace("Page onInitComplete()",'System.Web.UI.TPage');
- $this->onInitComplete(null);
+ $this->onInitComplete($this);
$this->_restPostData=new TMap;
Prado::trace("Page loadPageState()",'System.Web.UI.TPage');
@@ -308,7 +308,7 @@ class TPage extends TTemplateControl
Prado::trace("Page processPostData()",'System.Web.UI.TPage');
$this->processPostData($this->_postData,true);
Prado::trace("Page onPreLoad()",'System.Web.UI.TPage');
- $this->onPreLoad(null);
+ $this->onPreLoad($this);
Prado::trace("Page loadRecursive()",'System.Web.UI.TPage');
$this->loadRecursive();
@@ -326,17 +326,17 @@ class TPage extends TTemplateControl
$this->raisePostBackEvent();
*/
Prado::trace("Page onLoadComplete()",'System.Web.UI.TPage');
- $this->onLoadComplete(null);
+ $this->onLoadComplete($this);
Prado::trace("Page preRenderRecursive()",'System.Web.UI.TPage');
$this->preRenderRecursive();
Prado::trace("Page onPreRenderComplete()",'System.Web.UI.TPage');
- $this->onPreRenderComplete(null);
+ $this->onPreRenderComplete($this);
Prado::trace("Page savePageState()",'System.Web.UI.TPage');
$this->savePageState();
Prado::trace("Page onSaveStateComplete()",'System.Web.UI.TPage');
- $this->onSaveStateComplete(null);
+ $this->onSaveStateComplete($this);
/*
Prado::trace("Page renderControl()",'System.Web.UI.TPage');
@@ -1200,6 +1200,64 @@ class TPage extends TTemplateControl
}
}
+
+/**
+ * IPageEvents interface.
+ *
+ * IPageEvents interface has all the events a page uses during its life cycle.
+ *
+ * @author Brad Anderson <javalizard@gmail.com>
+ * @version $Id$
+ * @package System.Web.UI
+ * @since 3.2
+ */
+interface IPageEvents {
+ /**
+ * Raises 'OnDataBinding' event. (inherited from TControl)
+ */
+ public function onDataBinding($param);
+ /**
+ * This method is invoked when the control enters 'OnInit' stage. (inherited from TControl)
+ */
+ public function onInit($param);
+ /**
+ * Raises OnInitComplete event.
+ */
+ public function onInitComplete($param);
+ /**
+ * This method is invoked when the control enters 'OnLoad' stage. (inherited from TControl)
+ */
+ public function onLoad($param);
+ /**
+ * Raises OnLoadComplete event.
+ */
+ public function onLoadComplete($param);
+ /**
+ * Raises OnPreInit event.
+ */
+ public function onPreInit($param);
+ /**
+ * Raises OnPreLoad event.
+ */
+ public function onPreLoad($param);
+ /**
+ * This method is invoked when the control enters 'OnPreRender' stage. (inherited from TControl)
+ */
+ public function onPreRender($param);
+ /**
+ * Raises OnPreRenderComplete event.
+ */
+ public function onPreRenderComplete($param);
+ /**
+ * Raises OnSaveStateComplete event.
+ */
+ public function onSaveStateComplete($param);
+ /**
+ * This method is invoked when the control enters 'OnUnload' stage. (inherited from TControl)
+ */
+ public function onUnload($param);
+}
+
/**
* IPageStatePersister interface.
*