From 9c1e1d5efa7ebef6596e4d2dd8a42892648c8e1b Mon Sep 17 00:00:00 2001 From: xue <> Date: Fri, 23 Dec 2005 17:52:51 +0000 Subject: --- framework/Web/Services/TPageService.php | 66 ++++++++++++++++++++------------- framework/Web/THttpRequest.php | 40 +++++++++++++++----- 2 files changed, 71 insertions(+), 35 deletions(-) (limited to 'framework/Web') diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php index 485346e2..53ce9c58 100644 --- a/framework/Web/Services/TPageService.php +++ b/framework/Web/Services/TPageService.php @@ -27,14 +27,19 @@ Prado::using('System.Web.UI.TPageStatePersister'); * Pages that are available to client users are stored under a directory specified by * {@link setBasePath BasePath}. The directory may contain subdirectories. * A directory may be used to group together the pages serving for the similar goal. - * Each directory must contain a configuration file config.xml that is similar to the application - * configuration file. The only difference is that the page directory configuration - * contains a mapping between page IDs and page types. The page IDs are visible - * by client users while page types are used on the server side. + * A directory may contain a configuration file config.xml whose content + * is similar to that of application configuration file. + * * A page is requested via page path, which is a dot-connected directory names - * appended by the page ID. Assume '/Users/Admin' is the directory - * containing the page 'Update' whose type is UpdateUserPage. Then the page can - * be requested via 'Users.Admin.Update'. + * appended by the page name. Assume '/Users/Admin' is the directory + * containing the page 'Update'. Then the page can be requested via 'Users.Admin.Update'. + * + * Page name refers to the file name (without extension) of the page template. + * In order to differentiate from the common control template files, the extension + * name of the page template files must be '.page'. If there is a PHP file with + * the same page name under the same directory as the template file, that file + * will be considered as the page class file and the file name is the page class name. + * If such a file is not found, the page class is assumed as {@link TPage}. * * Modules can be configured and loaded in page directory configurations. * Configuration of a module in a subdirectory will overwrite its parent @@ -170,42 +175,53 @@ class TPageService extends TComponent implements IService else { $configCached=true; + $currentTimestamp=array(); $arr=$cache->get(self::CONFIG_CACHE_PREFIX.$this->_pagePath); if(is_array($arr)) { - list($pageConfig,$timestamp)=$arr; + list($pageConfig,$timestamps)=$arr; if($application->getMode()!==TApplication::STATE_PERFORMANCE) { - // check to see if cache is the latest - $paths=explode('.',$this->_pagePath); - array_pop($paths); - $configPath=$this->_basePath; - foreach($paths as $path) + foreach($timestamps as $fileName=>$timestamp) { - if(@filemtime($configPath.'/'.self::CONFIG_FILE)>$timestamp) + if($fileName===0) // application config file { - $configCached=false; - break; + $appConfigFile=$application->getConfigurationFile(); + $currentTimestamp[0]=$appConfigFile===null?0:@filemtime($appConfigFile); + if($currentTimestamp[0]>$timestamp || ($timestamp>0 && !$currentTimestamp[0])) + $configCached=false; + } + else + { + $currentTimestamp[$fileName]=@filemtime($fileName); + if($currentTimestamp[$fileName]>$timestamp || ($timestamp>0 && !$currentTimestamp[$fileName])) + $configCached=false; } - $configPath.='/'.$path; - } - if($configCached) - { - $appConfig=$application->getConfigurationFile(); - if(!$appConfig || @filemtime($appConfig)>$timestamp || @filemtime($configPath.'/'.self::CONFIG_FILE)>$timestamp) - $configCached=false; } } } else + { $configCached=false; + $paths=explode('.',$this->_pagePath); + array_pop($paths); + $configPath=$this->_basePath; + foreach($paths as $path) + { + $configFile=$configPath.'/'.self::CONFIG_FILE; + $currentTimestamp[$configFile]=@filemtime($configFile); + $configPath.='/'.$path; + } + $appConfigFile=$application->getConfigurationFile(); + $currentTimestamp[0]=$appConfigFile===null?0:@filemtime($appConfigFile); + } if(!$configCached) { $pageConfig=new TPageConfiguration; if($config!==null) $pageConfig->loadXmlElement($config,$application->getConfigurationPath(),null); $pageConfig->loadConfigurationFiles($this->_pagePath,$this->_basePath); - $cache->set(self::CONFIG_CACHE_PREFIX.$this->_pagePath,array($pageConfig,time())); + $cache->set(self::CONFIG_CACHE_PREFIX.$this->_pagePath,array($pageConfig,$currentTimestamp)); } } @@ -738,6 +754,4 @@ class TPageConfiguration extends TComponent } } - - ?> \ No newline at end of file diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php index 938e56a3..d42035df 100644 --- a/framework/Web/THttpRequest.php +++ b/framework/Web/THttpRequest.php @@ -64,6 +64,9 @@ class THttpRequest extends TModule */ private $_items; + private $_services; + private $_requestResolved=false; + /** * Initializes the module. * This method is required by IModule and is invoked by application. @@ -105,7 +108,6 @@ class THttpRequest extends TModule $this->_items=new TMap(array_merge($_POST,$_GET)); - $this->resolveRequest(); $this->_initialized=true; $application->setRequest($this); } @@ -338,9 +340,9 @@ class THttpRequest extends TModule public function constructUrl($serviceID,$serviceParam,$getItems=null) { $url=$this->getApplicationPath(); - $url.='?'.self::SERVICE_VAR.'='.$serviceID; + $url.='?'.$serviceID.'='; if(!empty($serviceParam)) - $url.='.'.$serviceParam; + $url.=$serviceParam; if(is_array($getItems) || $getItems instanceof Traversable) { foreach($getItems as $name=>$value) @@ -361,23 +363,41 @@ class THttpRequest extends TModule */ protected function resolveRequest() { - if(($sp=$this->_items->itemAt(self::SERVICE_VAR))!==null) + $this->_requestResolved=true; + foreach($this->_services as $id) { - if(($pos=strpos($sp,'.'))===false) - $this->setServiceID($sp); - else + if(isset($_GET[$id])) { - $this->setServiceID(substr($sp,0,$pos)); - $this->setServiceParameter(substr($sp,$pos+1)); + $this->setServiceID($id); + $this->setServiceParameter($_GET[$id]); + break; } } } + /** + * @return array IDs of the available services + */ + public function getAvailableServices() + { + return $this->_services; + } + + /** + * @param array IDs of the available services + */ + public function setAvailableServices($services) + { + $this->_services=$services; + } + /** * @return string requested service ID */ public function getServiceID() { + if(!$this->_requestResolved) + $this->resolveRequest(); return $this->_serviceID; } @@ -395,6 +415,8 @@ class THttpRequest extends TModule */ public function getServiceParameter() { + if(!$this->_requestResolved) + $this->resolveRequest(); return $this->_serviceParam; } -- cgit v1.2.3