From 869a2aa2bad745d7363833489b234e45a2200692 Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 19 Jun 2007 19:48:35 +0000 Subject: Fix the bug that tag was ignored in page configurations --- framework/Web/Services/TPageService.php | 55 ++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'framework/Web/Services/TPageService.php') 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; + } } } -- cgit v1.2.3