From b2b00ee68812dc455e5fe3ea816d7af16d500b2d Mon Sep 17 00:00:00 2001 From: javalizard <> Date: Wed, 14 Apr 2010 01:37:38 +0000 Subject: Adds getModulesByType, getIsAfterService, and onInitComplete for wrapping up the init processes should any modules need it before the beginning the request --- framework/TApplication.php | 55 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 5 deletions(-) (limited to 'framework/TApplication.php') diff --git a/framework/TApplication.php b/framework/TApplication.php index 22c871f7..2eba65fb 100644 --- a/framework/TApplication.php +++ b/framework/TApplication.php @@ -76,7 +76,8 @@ Prado::using('System.I18N.TGlobalization'); * 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 - * - onBeginRequest : this event happens right after application initialization + * - onInitComplete : this event happens right after application initialization and can finish any initialization + * - onBeginRequest : this event happens right before the request starts * - 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 @@ -160,6 +161,11 @@ class TApplication extends TComponent * Global data file */ const GLOBAL_FILE='global.cache'; + + /** + * Defines which step the service is run + */ + const SERVICE_STEP=8; /** * @var array list of events that define application lifecycles @@ -413,6 +419,15 @@ class TApplication extends TComponent } $this->onEndRequest(); } + + + /** + * Tells you whether the application is after the service step + * @return boolean whether it is after the service step + */ + public function getIsAfterService() { + return $this->_step > self::SERVICE_STEP; + } /** * Completes current request processing. @@ -700,6 +715,21 @@ class TApplication extends TComponent return isset($this->_modules[$id])?$this->_modules[$id]:null; } + /** + * This loops through all the modules and finds those with a specific type, with/witout strictness + * @param string $type this is the string module type to look for + * @param boolean $strict default false, the module can be an instanceof the type if false, otherwise it must be the exact class + * @return IModule the module with the specified ID, null if not found + */ + public function getModulesByType($type,$strict=false) + { + $modules = array(); + foreach($this->_modules as $module) + if( get_class($module)===$type || (!$strict && ($module instanceof $type)) ) + $modules[] = $module; + return $modules; + } + /** * @return array list of loaded application modules, indexed by module IDs */ @@ -1039,6 +1069,8 @@ class TApplication extends TComponent $serviceID=$this->getPageServiceID(); $this->startService($serviceID); + + $this->onInitComplete(); } /** @@ -1092,11 +1124,24 @@ class TApplication extends TComponent $this->getErrorHandler()->handleError($this,$param); } + /** + * Raises onInitComplete event. + * At the time when this method is invoked, application modules are loaded, + * user request is resolved and the corresponding service + * is loaded and initialized. The application is about to start processing + * the user request. + */ + public function onInitComplete() + { + Prado::trace("Executing onInitComplete()",'System.TApplication'); + $this->raiseEvent('onInitComplete',$this,null); + } + /** * Raises OnBeginRequest event. * At the time when this method is invoked, application modules are loaded * and initialized, user request is resolved and the corresponding service - * is loaded and initialized. The application is about to start processing + * is loaded and initialized. The application is starting to process * the user request. */ public function onBeginRequest() @@ -1798,11 +1843,11 @@ class TApplicationStatePersister extends TModule implements IStatePersister public function load() { if(($cache=$this->getApplication()->getCache())!==null && ($value=$cache->get(self::CACHE_NAME))!==false) - return unserialize($value); + return Prado::unserialize($value); else { if(($content=@file_get_contents($this->getStateFilePath()))!==false) - return unserialize($content); + return Prado::unserialize($content); else return null; } @@ -1814,7 +1859,7 @@ class TApplicationStatePersister extends TModule implements IStatePersister */ public function save($state) { - $content=serialize($state); + $content=Prado::serialize($state); $saveFile=true; if(($cache=$this->getApplication()->getCache())!==null) { -- cgit v1.2.3