summaryrefslogtreecommitdiff
path: root/framework/Web
diff options
context:
space:
mode:
authorxue <>2005-11-19 02:42:35 +0000
committerxue <>2005-11-19 02:42:35 +0000
commitbc1a7e1e3a67537189d30013ea6d5fa4bf98e8e4 (patch)
treecf4505fc457292ed5499b16d2412bd00ab14a0bd /framework/Web
parentc2b0b3123d351e1ec96203eb099e35c6d5c6bdc9 (diff)
Diffstat (limited to 'framework/Web')
-rw-r--r--framework/Web/TAssetManager.php17
-rw-r--r--framework/Web/THttpRequest.php2
-rw-r--r--framework/Web/UI/TThemeManager.php75
3 files changed, 66 insertions, 28 deletions
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,
+ * <module id="asset" BasePath="Application.assets" BaseUrl="/assets" />
+ * 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 <qiang.xue@gmail.com>
* @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 @@
<?php
+// TODO: use namespace for BasePath
+// add ThemesUrl
+
+
class TThemeManager extends TComponent implements IModule
{
const THEME_CACHE_PREFIX='prado:theme:';
- const DEFAULT_THEME_PATH='themes';
+ const DEFAULT_BASEPATH='themes';
/**
* @var string module ID
*/
@@ -15,7 +19,8 @@ class TThemeManager extends TComponent implements IModule
/**
* @var string the directory containing all themes
*/
- private $_themePath=null;
+ private $_basePath=null;
+ private $_baseUrl=null;
/**
* @var TApplication application
*/
@@ -30,9 +35,11 @@ class TThemeManager extends TComponent implements IModule
public function init($application,$config)
{
$this->_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)
{