diff options
author | javalizard <> | 2010-04-14 01:37:38 +0000 |
---|---|---|
committer | javalizard <> | 2010-04-14 01:37:38 +0000 |
commit | b2b00ee68812dc455e5fe3ea816d7af16d500b2d (patch) | |
tree | b595c6de2e3bb3493bb286440fe3531db1d0bcc0 /framework | |
parent | 29eb956e4a6904d7841d12716482357172e50c28 (diff) |
Adds getModulesByType, getIsAfterService, and onInitComplete for wrapping up the init processes should any modules need it before the beginning the request
Diffstat (limited to 'framework')
-rw-r--r-- | framework/TApplication.php | 55 |
1 files changed, 50 insertions, 5 deletions
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. @@ -701,6 +716,21 @@ class TApplication extends TComponent } /** + * 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 */ public function getModules() @@ -1039,6 +1069,8 @@ class TApplication extends TComponent $serviceID=$this->getPageServiceID(); $this->startService($serviceID); + + $this->onInitComplete(); } /** @@ -1093,10 +1125,23 @@ class TApplication extends TComponent } /** + * 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) { |