From bc1a7e1e3a67537189d30013ea6d5fa4bf98e8e4 Mon Sep 17 00:00:00 2001
From: xue <>
Date: Sat, 19 Nov 2005 02:42:35 +0000
Subject:
---
framework/Web/TAssetManager.php | 17 ++++++++-
framework/Web/THttpRequest.php | 2 +-
framework/Web/UI/TThemeManager.php | 75 +++++++++++++++++++++++++-------------
3 files changed, 66 insertions(+), 28 deletions(-)
(limited to 'framework/Web')
diff --git a/framework/Web/TAssetManager.php b/framework/Web/TAssetManager.php
index b48fed79..fa9e649e 100644
--- a/framework/Web/TAssetManager.php
+++ b/framework/Web/TAssetManager.php
@@ -29,6 +29,13 @@
* with the function {@link publishFilePath}. This is usually
* very useful during development.
*
+ * TAssetManager may be configured in application configuration file within
+ * page service element as follows,
+ *
+ * where {@link getBasePath BasePath} and {@link getBaseUrl BaseUrl} are
+ * configurable properties of TAssetManager. Make sure that BasePath is a namespace
+ * pointing to a valid directory writable by the Web server process.
+ *
* @author Qiang Xue
* @version $Revision: $ $Date: $
* @package System.Web
@@ -104,6 +111,8 @@ class TAssetManager extends TComponent implements IModule
}
/**
+ * Sets the root directory storing published asset files.
+ * The directory must be in namespace format.
* @param string the root directory storing published asset files
* @throws TInvalidOperationException if the service is initialized already
*/
@@ -111,8 +120,12 @@ class TAssetManager extends TComponent implements IModule
{
if($this->_initialized)
throw new TInvalidOperationException('assetmanager_basepath_unchangeable');
- else if(($this->_basePath=realpath($value))===false)
- throw new TInvalidDataValueException('assetmanage_basepath_invalid',$value);
+ else
+ {
+ $this->_basePath=Prado::getPathOfAlias($value);
+ if($this->_basePath===null || !is_dir($this->_basePath) || !is_writable($this->_basePath))
+ throw new TInvalidDataValueException('assetmanage_basepath_invalid',$value);
+ }
}
/**
diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php
index dd1bd662..59e65a7e 100644
--- a/framework/Web/THttpRequest.php
+++ b/framework/Web/THttpRequest.php
@@ -212,7 +212,7 @@ class THttpRequest extends TComponent implements IModule
}
/**
- * @return string application entry script file path
+ * @return string application entry script file path (processed w/ realpath())
*/
public function getPhysicalApplicationPath()
{
diff --git a/framework/Web/UI/TThemeManager.php b/framework/Web/UI/TThemeManager.php
index f98563e0..b51aecac 100644
--- a/framework/Web/UI/TThemeManager.php
+++ b/framework/Web/UI/TThemeManager.php
@@ -1,9 +1,13 @@
_application=$application;
- if($this->_themePath===null)
- $this->_themePath=dirname($application->getRequest()->getPhysicalApplicationPath()).'/'.self::DEFAULT_THEME_PATH;
-
+ if($this->_basePath===null)
+ $this->_basePath=dirname($application->getRequest()->getPhysicalApplicationPath()).'/'.self::DEFAULT_BASEPATH;
+ if(($basePath=realpath($this->_basePath))===false || !is_dir($basePath))
+ throw new TConfigurationException('thememanager_basepath_invalid',$this->_basePath);
+ $this->_basePath=$basePath;
$this->_initialized=true;
$application->getService()->setThemeManager($this);
}
@@ -55,9 +62,8 @@ class TThemeManager extends TComponent implements IModule
public function getTheme($name)
{
- $themePath=realpath($this->_themePath.'/'.$name);
- if($themePath===false || !is_dir($this->_themePath))
- throw new TConfigurationException('thememanager_themepath_invalid',$themePath);
+ if(($themePath=realpath($this->_basePath.'/'.$name))===false || !is_dir($themePath))
+ throw new TConfigurationException('thememanager_theme_inexistent',$name);
if(($cache=$this->_application->getCache())!==null)
{
$array=$cache->get(self::THEME_CACHE_PREFIX.$themePath);
@@ -68,7 +74,7 @@ class TThemeManager extends TComponent implements IModule
if($this->_application->getMode()!=='Performance')
{
if(($dir=opendir($themePath))===false)
- throw new TIOException('thememanager_themepath_invalid',$themePath);
+ throw new TIOException('thememanager_theme_inexistent',$name);
while(($file=readdir($dir))!==false)
{
if(basename($file,'.skin')!==$file && filemtime($themePath.'/'.$file)>$timestamp)
@@ -83,33 +89,49 @@ class TThemeManager extends TComponent implements IModule
return $theme;
}
}
- // not cached, so we parse all skin files
+ // not cached, so we collect all skin files
$content='';
if(($dir=opendir($themePath))===false)
- throw new TIOException('thememanager_themepath_invalid',$themePath);
+ throw new TIOException('thememanager_theme_inexistent',$name);
while(($file=readdir($dir))!==false)
{
if(basename($file,'.skin')!==$file)
$content.=file_get_contents($themePath.'/'.$file);
}
closedir($dir);
- $theme=new TTheme($content,$themePath);
+
+ $theme=new TTheme($content,$themePath,$this->_baseUrl);
if($cache!==null)
$cache->set(self::THEME_CACHE_PREFIX.$themePath,array($theme,time()));
return $theme;
}
- public function getThemePath()
+ public function getBasePath()
{
- return $this->_themePath;
+ return $this->_basePath;
}
- public function setThemePath($value)
+ public function setBasePath($value)
{
if($this->_initialized)
- throw new TInvalidOperationException('thememanager_themepath_unchangeable');
+ throw new TInvalidOperationException('thememanager_basepath_unchangeable');
else
- $this->_themePath=$value;
+ {
+ $this->_basePath=Prado::getPathOfAlias($value);
+ if($this->_basePath===null || !is_dir($this->_basePath))
+ throw new TInvalidDataValueException('thememanager_basepath_invalid',$value);
+ $this->_basePath=$value;
+ }
+ }
+
+ public function getBaseUrl()
+ {
+ return $this->_baseUrl;
+ }
+
+ public function setBaseUrl($value)
+ {
+ $this->_baseUrl=$value;
}
}
@@ -119,17 +141,20 @@ class TTheme extends TTemplate
private $_themeUrl;
private $_skins=array();
- public function __construct($content,$themePath)
+ public function __construct($content,$themePath,$baseUrl)
{
- $this->_themePath=realpath($themePath);
- $basePath=dirname(Prado::getApplication()->getRequest()->getPhysicalApplicationPath());
- if($this->_themePath===false || ($pos=strpos($this->_themePath,$basePath))===false)
- throw new TConfigurationException('theme_themepath_invalid',$themePath);
- else
+ $this->_themePath=$themePath;
+ if($baseUrl===null)
{
- $baseUrl=dirname(Prado::getApplication()->getRequest()->getApplicationPath());
- $this->_themeUrl=$baseUrl.'/'.strtr(substr($this->_themePath,strlen($basePath)),'\\','/');
+ $appPath=dirname(Prado::getApplication()->getRequest()->getPhysicalApplicationPath());
+ if(strpos($themePath,$appPath)===false)
+ throw new TConfigurationException('theme_baseurl_required');
+ $appUrl=dirname(Prado::getApplication()->getRequest()->getApplicationPath());
+ $this->_themeUrl=$appUrl.'/'.strtr(substr($theme,strlen($basePath)),'\\','/');
}
+ else
+ $this->_themeUrl=$baseUrl.'/'.basename($themePath);
+
$theme=&$this->parse($content);
foreach($theme as $skin)
{
--
cgit v1.2.3