From a79a69ca2e9f1818c0c4c276fd4857e4f849ab80 Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 27 Dec 2005 04:11:43 +0000 Subject: Introduced application base path concept. --- framework/Exceptions/messages.txt | 2 +- framework/TApplication.php | 47 +++++++++++++++------------------ framework/Web/Services/TPageService.php | 6 ++--- 3 files changed, 25 insertions(+), 30 deletions(-) (limited to 'framework') diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt index d32b3005..c31c49d2 100644 --- a/framework/Exceptions/messages.txt +++ b/framework/Exceptions/messages.txt @@ -23,7 +23,7 @@ map_addition_disallowed = The new item cannot be added to the map. map_item_unremovable = The item cannot be removed from the map. map_data_not_iterable = Data must be either an array or an object implementing Traversable interface. -application_configpath_inexistent = Application configuration path '%s' does not exist. +application_basepath_invalid = Application base path '%s' does not exist or is not a directory. application_runtimepath_invalid = Application runtime path '%s' does not exist or is not writable by Web server process. application_service_invalid = Service '%s' must implement IService interface. application_service_unknown = Requested service '%s' is not defined. diff --git a/framework/TApplication.php b/framework/TApplication.php index 716c35b5..104ff795 100644 --- a/framework/TApplication.php +++ b/framework/TApplication.php @@ -191,9 +191,9 @@ class TApplication extends TComponent */ private $_configFile; /** - * @var string configuration path + * @var string application base path */ - private $_configPath; + private $_basePath; /** * @var string directory storing application state */ @@ -245,13 +245,19 @@ class TApplication extends TComponent /** * Constructor. - * Initializes the application singleton. This method ensures that users can - * only create one application instance. - * @param string configuration file path (absolute or relative to current running script) + * Sets application base path and initializes the application singleton. + * Application base path refers to the root directory where application + * data and code not directly accessible by Web users are stored. + * If there is a file named application.xml under the base path, + * it is assumed to be the application configuration file and will be loaded + * and parsed when the application runs. By default, the base path is assumed + * to be the protected directory under the directory containing + * the current running script. + * @param string application base path (absolute or relative to current running script) * @param boolean whether to cache application configuration. Defaults to true. * @throws TConfigurationException if configuration file cannot be read or the runtime path is invalid. */ - public function __construct($configPath=null,$cacheConfig=true) + public function __construct($basePath='protected',$cacheConfig=true) { parent::__construct(); @@ -259,31 +265,20 @@ class TApplication extends TComponent Prado::setApplication($this); // determine configuration path and file - if($configPath===null) - $configPath=dirname($_SERVER['SCRIPT_FILENAME']).'/protected'; - if(($this->_configPath=realpath($configPath))===false) - throw new TConfigurationException('application_configpath_inexistent',$configPath); - if(is_dir($this->_configPath)) - { - $configFile=$this->_configPath.'/'.self::CONFIG_FILE; - $this->_configFile=is_file($configFile) ? $configFile : null; - } - else - { - $this->_configFile=$this->_configPath; - $this->_configPath=dirname($this->_configPath); - } - $this->_runtimePath=$this->_configPath.'/'.self::RUNTIME_PATH; + if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath)) + throw new TConfigurationException('application_basepath_invalid',$basePath); + $configFile=$this->_basePath.'/'.self::CONFIG_FILE; + $this->_configFile=is_file($configFile) ? $configFile : null; + $this->_runtimePath=$this->_basePath.'/'.self::RUNTIME_PATH; if(!is_dir($this->_runtimePath) || !is_writable($this->_runtimePath)) throw new TConfigurationException('application_runtimepath_invalid',$this->_runtimePath); $this->_cacheFile=$cacheConfig ? $this->_runtimePath.'/'.self::CONFIGCACHE_FILE : null; // generates unique ID by hashing the configuration path - $this->_uniqueID=md5($this->_configPath); + $this->_uniqueID=md5($this->_basePath); } - /** * Executes the lifecycles of the application. * This is the main entry function that leads to the running of the whole @@ -455,9 +450,9 @@ class TApplication extends TComponent /** * @return string configuration path */ - public function getConfigurationPath() + public function getBasePath() { - return $this->_configPath; + return $this->_basePath; } /** @@ -683,7 +678,7 @@ class TApplication extends TComponent */ protected function initApplication() { - Prado::setPathOfAlias('Application',$this->_configPath); + Prado::setPathOfAlias('Application',$this->_basePath); if($this->_configFile===null) { diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php index 886fec24..d94b7ae2 100644 --- a/framework/Web/Services/TPageService.php +++ b/framework/Web/Services/TPageService.php @@ -154,7 +154,7 @@ class TPageService extends TService if($this->_basePath===null) { - $basePath=$application->getConfigurationPath().'/'.self::DEFAULT_BASEPATH; + $basePath=$application->getBasePath().'/'.self::DEFAULT_BASEPATH; if(($this->_basePath=realpath($basePath))===false || !is_dir($this->_basePath)) throw new TConfigurationException('pageservice_basepath_invalid',$basePath); } @@ -169,7 +169,7 @@ class TPageService extends TService { $pageConfig=new TPageConfiguration; if($config!==null) - $pageConfig->loadXmlElement($config,$application->getConfigurationPath(),null); + $pageConfig->loadXmlElement($config,$application->getBasePath(),null); $pageConfig->loadConfigurationFiles($this->_pagePath,$this->_basePath); } else @@ -219,7 +219,7 @@ class TPageService extends TService { $pageConfig=new TPageConfiguration; if($config!==null) - $pageConfig->loadXmlElement($config,$application->getConfigurationPath(),null); + $pageConfig->loadXmlElement($config,$application->getBasePath(),null); $pageConfig->loadConfigurationFiles($this->_pagePath,$this->_basePath); $cache->set(self::CONFIG_CACHE_PREFIX.$this->_pagePath,array($pageConfig,$currentTimestamp)); } -- cgit v1.2.3