summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
authorxue <>2007-06-19 19:48:35 +0000
committerxue <>2007-06-19 19:48:35 +0000
commit869a2aa2bad745d7363833489b234e45a2200692 (patch)
treeae8268e64b02b29abf65003dfe3c095df5e471f3 /framework/Web
parentfb16cd829679f1459d3a6541d1bd4997c0c96d29 (diff)
Fix the bug that <include> tag was ignored in page configurations
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/Services/TPageService.php55
1 files changed, 51 insertions, 4 deletions
diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php
index 58b7d57b..343508b8 100644
--- a/framework/Web/Services/TPageService.php
+++ b/framework/Web/Services/TPageService.php
@@ -154,14 +154,36 @@ class TPageService extends TService
protected function initPageContext($pageConfig)
{
$application=$this->getApplication();
-
foreach($pageConfig->getApplicationConfigurations() as $appConfig)
$application->applyConfiguration($appConfig);
+ $this->applyConfiguration($pageConfig);
+ }
+
+ /**
+ * Applies a page configuration.
+ * @param TPageConfiguration the configuration
+ */
+ protected function applyConfiguration($config)
+ {
// initial page properties (to be set when page runs)
- $this->_properties=$pageConfig->getProperties();
+ $this->_properties=$config->getProperties();
+ $this->getApplication()->getAuthorizationRules()->mergeWith($config->getRules());
+ // external configurations
+ foreach($config->getExternalConfigurations() as $filePath=>$condition)
+ {
+ if($condition!==true)
+ $condition=$this->evaluateExpression($condition);
+ if($condition)
+ {
+ if(($path=Prado::getPathOfNamespace($filePath,TApplication::CONFIG_FILE_EXT))===null || !is_file($path))
+ throw new TConfigurationException('pageservice_includefile_invalid',$filePath);
+ $c=new TPageConfiguration;
+ $c->loadFromFile($path,null);
+ $this->applyConfiguration($c);
+ }
+ }
- $application->getAuthorizationRules()->mergeWith($pageConfig->getRules());
}
/**
@@ -483,6 +505,18 @@ class TPageConfiguration extends TComponent
* @var TAuthorizationRuleCollection list of authorization rules
*/
private $_rules=array();
+ /**
+ * @var array list of included configurations
+ */
+ private $_includes=array();
+
+ /**
+ * @return array list of external configuration files. Each element is like $filePath=>$condition
+ */
+ public function getExternalConfigurations()
+ {
+ return $this->_includes;
+ }
/**
* Returns list of page initial property values.
@@ -538,7 +572,7 @@ class TPageConfiguration extends TComponent
* @param string config file name
* @param string page name, null if page is not required
*/
- private function loadFromFile($fname,$page)
+ public function loadFromFile($fname,$page)
{
Prado::trace("Loading $page with file $fname",'System.Web.Services.TPageService');
if(empty($fname) || !is_file($fname))
@@ -628,6 +662,19 @@ class TPageConfiguration extends TComponent
}
}
}
+
+ // external configurations
+ foreach($dom->getElementsByTagName('include') as $node)
+ {
+ if(($when=$node->getAttribute('when'))===null)
+ $when=true;
+ if(($filePath=$node->getAttribute('file'))===null)
+ throw new TConfigurationException('pageserviceconf_includefile_required');
+ if(isset($this->_includes[$filePath]))
+ $this->_includes[$filePath]='('.$this->_includes[$filePath].') || ('.$when.')';
+ else
+ $this->_includes[$filePath]=$when;
+ }
}
}