summaryrefslogtreecommitdiff
path: root/framework/TApplication.php
diff options
context:
space:
mode:
authorCiro Mattia Gonano <ciromattia@gmail.com>2013-07-24 12:22:49 +0200
committerCiro Mattia Gonano <ciromattia@gmail.com>2013-07-24 12:22:49 +0200
commit0f332e6564ed67ef7eb4d715ce3bcb5ff54c50cf (patch)
tree00cecb80224872c25e712a59b417c5f1dff240cb /framework/TApplication.php
parent3c208455c7775838e795909923536a7de13d9c5c (diff)
Upgrade to newly released 3.2.23.2.2
Diffstat (limited to 'framework/TApplication.php')
-rw-r--r--framework/TApplication.php73
1 files changed, 52 insertions, 21 deletions
diff --git a/framework/TApplication.php b/framework/TApplication.php
index 6a404bcc..a4a4b423 100644
--- a/framework/TApplication.php
+++ b/framework/TApplication.php
@@ -6,7 +6,7 @@
* @link http://www.pradosoft.com/
* @copyright Copyright &copy; 2005-2013 PradoSoft
* @license http://www.pradosoft.com/license/
- * @version $Id: TApplication.php 3245 2013-01-07 20:23:32Z ctrlaltca $
+ * @version $Id: TApplication.php 3272 2013-02-13 21:43:28Z ctrlaltca $
* @package System
*/
@@ -105,7 +105,7 @@ Prado::using('System.I18N.TGlobalization');
* </code>
*
* @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id: TApplication.php 3245 2013-01-07 20:23:32Z ctrlaltca $
+ * @version $Id: TApplication.php 3272 2013-02-13 21:43:28Z ctrlaltca $
* @package System
* @since 3.0
*/
@@ -205,10 +205,14 @@ class TApplication extends TComponent
*/
private $_service;
/**
- * @var array list of application modules
+ * @var array list of loaded application modules
*/
private $_modules=array();
/**
+ * @var array list of application modules yet to be loaded
+ */
+ private $_lazyModules=array();
+ /**
* @var TMap list of application parameters
*/
private $_parameters;
@@ -607,7 +611,7 @@ class TApplication extends TComponent
}
/**
- * @return string the applictaion configuration type. default is 'xml'
+ * @return string the application configuration type. default is 'xml'
*/
public function getConfigurationFileExt()
{
@@ -685,9 +689,9 @@ class TApplication extends TComponent
* Adds a module to application.
* Note, this method does not do module initialization.
* @param string ID of the module
- * @param IModule module object
+ * @param IModule module object or null if the module has not been loaded yet
*/
- public function setModule($id,IModule $module)
+ public function setModule($id,IModule $module=null)
{
if(isset($this->_modules[$id]))
throw new TConfigurationException('application_moduleid_duplicated',$id);
@@ -700,10 +704,22 @@ class TApplication extends TComponent
*/
public function getModule($id)
{
- return isset($this->_modules[$id])?$this->_modules[$id]:null;
+ if(!array_key_exists($id, $this->_modules))
+ return null;
+
+ // force loading of a lazy module
+ if($this->_modules[$id]===null)
+ {
+ $module = $this->internalLoadModule($id, true);
+ $module[0]->init($module[1]);
+ }
+
+ return $this->_modules[$id];
}
/**
+ * Returns a list of application modules indexed by module IDs.
+ * Modules that have not been loaded yet are returned as null objects.
* @return array list of loaded application modules, indexed by module IDs
*/
public function getModules()
@@ -938,6 +954,28 @@ class TApplication extends TComponent
return 'TApplicationConfiguration';
}
+ protected function internalLoadModule($id, $force=false)
+ {
+ list($moduleClass, $initProperties, $configElement)=$this->_lazyModules[$id];
+ if(isset($initProperties['lazy']) && $initProperties['lazy'] && !$force)
+ {
+ Prado::trace("Postponed loading of lazy module $id ({$moduleClass})",'System.TApplication');
+ $this->setModule($id, null);
+ return null;
+ }
+
+ Prado::trace("Loading module $id ({$moduleClass})",'System.TApplication');
+ $module=Prado::createComponent($moduleClass);
+ foreach($initProperties as $name=>$value)
+ {
+ if($name==='lazy') continue;
+ $module->setSubProperty($name,$value);
+ }
+ $this->setModule($id,$module);
+ unset($this->_lazyModules[$id]);
+
+ return array($module,$configElement);
+ }
/**
* Applies an application configuration.
* @param TApplicationConfiguration the configuration
@@ -982,18 +1020,11 @@ class TApplication extends TComponent
$modules=array();
foreach($config->getModules() as $id=>$moduleConfig)
{
- Prado::trace("Loading module $id ({$moduleConfig[0]})",'System.TApplication');
- list($moduleClass, $initProperties, $configElement)=$moduleConfig;
- $module=Prado::createComponent($moduleClass);
if(!is_string($id))
- {
- $id='_module'.count($this->_modules);
- $initProperties['id']=$id;
- }
- $this->setModule($id,$module);
- foreach($initProperties as $name=>$value)
- $module->setSubProperty($name,$value);
- $modules[]=array($module,$configElement);
+ $id='_module'.count($this->_lazyModules);
+ $this->_lazyModules[$id]=$moduleConfig;
+ if($module = $this->internalLoadModule($id))
+ $modules[]=$module;
}
foreach($modules as $module)
$module[0]->init($module[1]);
@@ -1248,7 +1279,7 @@ class TApplication extends TComponent
* - Normal: the application is running in normal production mode.
* - Performance: the application is running in performance mode.
* @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id: TApplication.php 3245 2013-01-07 20:23:32Z ctrlaltca $
+ * @version $Id: TApplication.php 3272 2013-02-13 21:43:28Z ctrlaltca $
* @package System
* @since 3.0.4
*/
@@ -1268,7 +1299,7 @@ class TApplicationMode extends TEnumerable
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Carl G. Mathisen <carlgmathisen@gmail.com>
- * @version $Id: TApplication.php 3245 2013-01-07 20:23:32Z ctrlaltca $
+ * @version $Id: TApplication.php 3272 2013-02-13 21:43:28Z ctrlaltca $
* @package System
* @since 3.0
*/
@@ -1777,7 +1808,7 @@ class TApplicationConfiguration extends TComponent
* Cache will be exploited if it is enabled.
*
* @author Qiang Xue <qiang.xue@gmail.com>
- * @version $Id: TApplication.php 3245 2013-01-07 20:23:32Z ctrlaltca $
+ * @version $Id: TApplication.php 3272 2013-02-13 21:43:28Z ctrlaltca $
* @package System
* @since 3.0
*/