summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxue <>2005-12-27 04:11:43 +0000
committerxue <>2005-12-27 04:11:43 +0000
commita79a69ca2e9f1818c0c4c276fd4857e4f849ab80 (patch)
tree41bf94449bf57bebc934aa7871b7691522bc6846
parente62f17f80a7cfd6f89f74fe6f2062850f54d1477 (diff)
Introduced application base path concept.
-rw-r--r--demos/personal/index.php3
-rw-r--r--demos/quickstart/index.php3
-rw-r--r--demos/quickstart/protected/pages/Fundamentals/Services.page2
-rw-r--r--framework/Exceptions/messages.txt2
-rw-r--r--framework/TApplication.php47
-rw-r--r--framework/Web/Services/TPageService.php6
6 files changed, 28 insertions, 35 deletions
diff --git a/demos/personal/index.php b/demos/personal/index.php
index 174f5d33..04695b16 100644
--- a/demos/personal/index.php
+++ b/demos/personal/index.php
@@ -2,7 +2,6 @@
$basePath=dirname(__FILE__);
$frameworkPath=$basePath.'/../../framework/prado.php';
-$configPath=$basePath.'/protected/application.xml';
$assetsPath=$basePath.'/assets';
if(!is_writable($assetsPath))
@@ -10,7 +9,7 @@ if(!is_writable($assetsPath))
require_once($frameworkPath);
-$application=new TApplication($configPath,true);
+$application=new TApplication;
$application->run();
?> \ No newline at end of file
diff --git a/demos/quickstart/index.php b/demos/quickstart/index.php
index 174f5d33..04695b16 100644
--- a/demos/quickstart/index.php
+++ b/demos/quickstart/index.php
@@ -2,7 +2,6 @@
$basePath=dirname(__FILE__);
$frameworkPath=$basePath.'/../../framework/prado.php';
-$configPath=$basePath.'/protected/application.xml';
$assetsPath=$basePath.'/assets';
if(!is_writable($assetsPath))
@@ -10,7 +9,7 @@ if(!is_writable($assetsPath))
require_once($frameworkPath);
-$application=new TApplication($configPath,true);
+$application=new TApplication;
$application->run();
?> \ No newline at end of file
diff --git a/demos/quickstart/protected/pages/Fundamentals/Services.page b/demos/quickstart/protected/pages/Fundamentals/Services.page
index 500929ba..0ed976c9 100644
--- a/demos/quickstart/protected/pages/Fundamentals/Services.page
+++ b/demos/quickstart/protected/pages/Fundamentals/Services.page
@@ -16,7 +16,7 @@ Developers may implement additional services for their applications. To make a s
<h2>Page Service</h2>
<p>
-TBD
+PRADO implements <code>TPageService</code> to process users' page requests.
</p>
</com:TContent> \ No newline at end of file
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 <b>application.xml</b> 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 <b>protected</b> 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));
}