diff options
author | xue <> | 2005-11-11 22:45:22 +0000 |
---|---|---|
committer | xue <> | 2005-11-11 22:45:22 +0000 |
commit | 51083f666005194dbed2e6963c823c08393a3a80 (patch) | |
tree | ea9c175659a0e0ad3036e2930ed048cf188dee0b | |
parent | cb9ad614fe9e811a1565878ffbfb37803fa30486 (diff) |
Enhanced page service configuration parsing. Content included between opening and closing page service tag in app config is now parsed.
-rw-r--r-- | demos/controls/protected/application.xml | 24 | ||||
-rw-r--r-- | framework/TApplication.php | 11 | ||||
-rw-r--r-- | framework/Web/Services/TPageService.php | 128 | ||||
-rw-r--r-- | tests/UnitTests/framework/utComponent.php | 10 |
4 files changed, 130 insertions, 43 deletions
diff --git a/demos/controls/protected/application.xml b/demos/controls/protected/application.xml index 6211399b..ef8280d6 100644 --- a/demos/controls/protected/application.xml +++ b/demos/controls/protected/application.xml @@ -4,18 +4,26 @@ <paths>
<alias id="Demo" path="." />
</paths>
+ <!-- modules configured and loaded for all services -->
<modules>
- <!--
+ <!-- make sure the path "protected" is writable by web server process if you enable this cache
<module id="cache" type="System.Data.TSqliteCache" DbFile="Demo.cache"/>
- -->
+ -->
<module id="session" type="THttpSession" />
- <module id="users" type="System.Security.TUserManager" PasswordMode="Clear">
- <user name="xue" password="qiang" />
- <user name="xue2" password="qiang2" />
- </module>
- <module id="auth" type="System.Security.TAuthManager" UserManager="users" LoginPage="login" />
</modules>
<services>
- <service id="page" RootPath="Demo.pages" DefaultPage="home" />
+ <!-- page service, PageRootPath is required -->
+ <service id="page" PageRootPath="Demo.pages" DefaultPage="home">
+ <!-- modules configured and loaded when page service is requested -->
+ <modules>
+ <!-- user manager module -->
+ <module id="users" type="System.Security.TUserManager" PasswordMode="Clear">
+ <user name="demo" password="work" />
+ <user name="demo2" password="work2" />
+ </module>
+ <!-- auth manager module -->
+ <module id="auth" type="System.Security.TAuthManager" UserManager="users" LoginPage="login" />
+ </modules>
+ </service>
</services>
</configuration>
\ No newline at end of file diff --git a/framework/TApplication.php b/framework/TApplication.php index 55c1df6c..70b6a9ff 100644 --- a/framework/TApplication.php +++ b/framework/TApplication.php @@ -141,7 +141,8 @@ class TApplication extends TComponent implements IApplication {
parent::__construct();
Prado::setApplication($this);
- $this->_configFile=$configFile;
+ if(($this->_configFile=realpath($configFile))===false)
+ throw new TIOException('application_configfile_invalid',$configFile);
$this->_cacheFile=$cacheFile;
}
@@ -207,6 +208,14 @@ class TApplication extends TComponent implements IApplication }
/**
+ * @return string configuration file path
+ */
+ public function getConfigurationFile()
+ {
+ return $this->_configFile;
+ }
+
+ /**
* @return IService the currently requested service
*/
public function getService()
diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php index 0ab1b7bf..e4791543 100644 --- a/framework/Web/Services/TPageService.php +++ b/framework/Web/Services/TPageService.php @@ -38,7 +38,7 @@ class TPageService extends TComponent implements IService /**
* @var string root path of pages
*/
- private $_rootPath;
+ private $_pageRootPath;
/**
* @var string default page
*/
@@ -52,6 +52,14 @@ class TPageService extends TComponent implements IService */
private $_pageType;
/**
+ * @var string the base URL for accessing published assets
+ */
+ private $_assetBaseUrl;
+ /**
+ * @var string the root path for storing published asset files
+ */
+ private $_assetRootPath;
+ /**
* @var array list of initial page property values
*/
private $_properties;
@@ -78,8 +86,8 @@ class TPageService extends TComponent implements IService {
$this->_application=$application;
- if(($rootPath=Prado::getPathOfNamespace($this->_rootPath))===null || !is_dir($rootPath))
- throw new TConfigurationException('pageservice_rootpath_invalid',$this->_rootPath);
+ if(($pageRootPath=Prado::getPathOfNamespace($this->_pageRootPath))===null || !is_dir($pageRootPath))
+ throw new TConfigurationException('pageservice_pagerootpath_invalid',$this->_pageRootPath);
$this->_pagePath=$application->getRequest()->getServiceParameter();
if(empty($this->_pagePath))
@@ -89,8 +97,9 @@ class TPageService extends TComponent implements IService if(($cache=$application->getCache())===null)
{
- $config=new TPageConfiguration;
- $config->loadConfiguration($this->_pagePath,$rootPath);
+ $pageConfig=new TPageConfiguration;
+ $pageConfig->loadXmlElement($config,dirname($application->getConfigurationFile()),null);
+ $pageConfig->loadConfigurationFiles($this->_pagePath,$pageRootPath);
}
else
{
@@ -98,13 +107,13 @@ class TPageService extends TComponent implements IService $arr=$cache->get(self::CONFIG_CACHE_PREFIX.$this->_pagePath);
if(is_array($arr))
{
- list($config,$timestamp)=$arr;
+ list($pageConfig,$timestamp)=$arr;
if($this->_cacheExpire<0)
{
// check to see if cache is the latest
$paths=explode('.',$this->_pagePath);
array_pop($paths);
- $configPath=$rootPath;
+ $configPath=$pageRootPath;
foreach($paths as $path)
{
if(@filemtime($configPath.'/'.self::CONFIG_FILE)>$timestamp)
@@ -114,7 +123,7 @@ class TPageService extends TComponent implements IService }
$configPath.='/'.$path;
}
- if(@filemtime($configPath.'/'.self::CONFIG_FILE)>$timestamp)
+ if($configCached && (@filemtime($application->getConfigurationFile())>$timestamp || @filemtime($configPath.'/'.self::CONFIG_FILE)>$timestamp))
$configCached=false;
}
}
@@ -122,25 +131,26 @@ class TPageService extends TComponent implements IService $configCached=false;
if(!$configCached)
{
- $config=new TPageConfiguration;
- $config->loadConfiguration($this->_pagePath,$rootPath);
- $cache->set(self::CONFIG_CACHE_PREFIX.$this->_pagePath,array($config,time()),$this->_cacheExpire<0?0:$this->_cacheExpire);
+ $pageConfig=new TPageConfiguration;
+ $pageConfig->loadXmlElement($config,dirname($application->getConfigurationFile()),null);
+ $pageConfig->loadConfigurationFiles($this->_pagePath,$pageRootPath);
+ $cache->set(self::CONFIG_CACHE_PREFIX.$this->_pagePath,array($pageConfig,time()),$this->_cacheExpire<0?0:$this->_cacheExpire);
}
}
- $this->_pageType=$config->getPageType();
+ $this->_pageType=$pageConfig->getPageType();
// set path aliases and using namespaces
- foreach($config->getAliases() as $alias=>$path)
+ foreach($pageConfig->getAliases() as $alias=>$path)
Prado::setPathAlias($alias,$path);
- foreach($config->getUsings() as $using)
+ foreach($pageConfig->getUsings() as $using)
Prado::using($using);
- $this->_properties=$config->getProperties();
+ $this->_properties=$pageConfig->getProperties();
// load parameters
$parameters=$application->getParameters();
- foreach($config->getParameters() as $id=>$parameter)
+ foreach($pageConfig->getParameters() as $id=>$parameter)
{
if(is_string($parameter))
$parameters->add($id,$parameter);
@@ -154,7 +164,7 @@ class TPageService extends TComponent implements IService }
// load modules specified in app config
- foreach($config->getModules() as $id=>$moduleConfig)
+ foreach($pageConfig->getModules() as $id=>$moduleConfig)
{
$module=Prado::createComponent($moduleConfig[0]);
$application->setModule($id,$module);
@@ -164,7 +174,7 @@ class TPageService extends TComponent implements IService }
if(($auth=$application->getAuthManager())!==null)
- $auth->getAuthorizationRules()->mergeWith($config->getRules());
+ $auth->getAuthorizationRules()->mergeWith($pageConfig->getRules());
$this->_initialized=true;
}
@@ -194,6 +204,14 @@ class TPageService extends TComponent implements IService }
/**
+ * @return TAssetManager asset manager
+ */
+ public function getAssetManager()
+ {
+ return $this->_application->getModule('asset');
+ }
+
+ /**
* @return boolean true if the pagepath is currently being requested, false otherwise
*/
public function isRequestingPage($pagePath)
@@ -256,21 +274,61 @@ class TPageService extends TComponent implements IService /**
* @return string root directory (in namespace form) storing pages
*/
- public function getRootPath()
+ public function getPageRootPath()
{
- return $this->_rootPath;
+ return $this->_pageRootPath;
}
/**
* @param string root directory (in namespace form) storing pages
- * @throws TInvalidOperationException if application is initialized
+ * @throws TInvalidOperationException if the service is initialized already
*/
- public function setRootPath($value)
+ public function setPageRootPath($value)
{
if($this->_initialized)
- throw new TInvalidOperationException('pageservice_rootpath_unchangeable');
+ throw new TInvalidOperationException('pageservice_pagerootpath_unchangeable');
else
- $this->_rootPath=$value;
+ $this->_pageRootPath=$value;
+ }
+
+ /**
+ * @return string the root directory storing published asset files
+ */
+ public function getAssetRootPath()
+ {
+ return $this->_assetRootPath;
+ }
+
+ /**
+ * @param string the root directory storing published asset files
+ * @throws TInvalidOperationException if the service is initialized already
+ */
+ public function setAssetRootPath($value)
+ {
+ if($this->_initialized)
+ throw new TInvalidOperationException('pageservice_assetrootpath_unchangeable');
+ else
+ $this->_assetRootPath=$value;
+ }
+
+ /**
+ * @return string the base url that the published asset files can be accessed
+ */
+ public function getAssetBaseUrl()
+ {
+ return $this->_assetBaseUrl;
+ }
+
+ /**
+ * @param string the base url that the published asset files can be accessed
+ * @throws TInvalidOperationException if the service is initialized already
+ */
+ public function setAssetBaseUrl($value)
+ {
+ if($this->_initialized)
+ throw new TInvalidOperationException('pageservice_assetbaseurl_unchangeable');
+ else
+ $this->_assetBaseUrl=$value;
}
/**
@@ -289,7 +347,7 @@ class TPageService extends TComponent implements IService $p=explode('.',$this->_pagePath);
array_pop($p);
array_push($p,$className);
- $path=Prado::getPathOfNamespace($this->_rootPath).'/'.implode('/',$p).Prado::CLASS_FILE_EXT;
+ $path=Prado::getPathOfNamespace($this->_pageRootPath).'/'.implode('/',$p).Prado::CLASS_FILE_EXT;
require_once($path);
}
}
@@ -361,6 +419,7 @@ class TPageConfiguration extends TComponent */
private $_modules=array(
'template'=>array('System.Web.UI.TTemplateManager',array(),null),
+ //'asset'=>array('System.Web.TAssetManager',array(),null)
);
/**
* @var array list of parameters
@@ -466,11 +525,11 @@ class TPageConfiguration extends TComponent * @param string path to the page (dot-connected format)
* @param string root path for pages
*/
- public function loadConfiguration($pagePath,$rootPath)
+ public function loadConfigurationFiles($pagePath,$pageRootPath)
{
$paths=explode('.',$pagePath);
$page=array_pop($paths);
- $path=$rootPath;
+ $path=$pageRootPath;
foreach($paths as $p)
{
$this->loadFromFile($path.'/'.TPageService::CONFIG_FILE,null);
@@ -492,10 +551,21 @@ class TPageConfiguration extends TComponent if($page===null)
return;
}
- $configPath=dirname($fname);
$dom=new TXmlDocument;
- $dom->loadFromFile($fname);
+ if($dom->loadFromFile($fname))
+ $this->loadXmlElement($dom,dirname($fname),$page);
+ else
+ throw new TConfigurationException('pageservice_configfile_invalid',$fname);
+ }
+ /**
+ * Loads a specific configuration xml element.
+ * @param TXmlElement config xml element
+ * @param string base path corresponding to this xml element
+ * @param string page name, null if page is not required
+ */
+ public function loadXmlElement($dom,$configPath,$page)
+ {
// paths
if(($pathsNode=$dom->getElementByTagName('paths'))!==null)
{
diff --git a/tests/UnitTests/framework/utComponent.php b/tests/UnitTests/framework/utComponent.php index 2683652a..07be4577 100644 --- a/tests/UnitTests/framework/utComponent.php +++ b/tests/UnitTests/framework/utComponent.php @@ -110,15 +110,15 @@ class utComponent extends UnitTestCase }
}
- public function testGetPropertyByPath()
+ public function testGetSubProperty()
{
- $this->assertTrue('object text'===$this->component->getPropertyByPath('Object.Text'));
+ $this->assertTrue('object text'===$this->component->getSubProperty('Object.Text'));
}
- public function testSetPropertyByPath()
+ public function testSetSubProperty()
{
- $this->component->setPropertyByPath('Object.Text','new object text');
- $this->assertEqual('new object text',$this->component->getPropertyByPath('Object.Text'));
+ $this->component->setSubProperty('Object.Text','new object text');
+ $this->assertEqual('new object text',$this->component->getSubProperty('Object.Text'));
}
public function testHasEvent()
|