diff options
author | xue <> | 2005-11-17 22:10:48 +0000 |
---|---|---|
committer | xue <> | 2005-11-17 22:10:48 +0000 |
commit | 3b613bc84c80307b6d93443b9989ca576bf59776 (patch) | |
tree | c8c145710ca990f58898ccf5b3664d5d185057bb /framework | |
parent | 5f88fccb2aa110929880085152e962f3c1769520 (diff) |
Diffstat (limited to 'framework')
-rw-r--r-- | framework/Web/Services/TPageService.php | 52 | ||||
-rw-r--r-- | framework/Web/TAssetManager.php | 1 | ||||
-rw-r--r-- | framework/Web/UI/TTemplateControl.php | 9 | ||||
-rw-r--r-- | framework/Web/UI/TTemplateManager.php | 6 | ||||
-rw-r--r-- | framework/Web/UI/TTheme.php | 168 | ||||
-rw-r--r-- | framework/Web/UI/TThemeManager.php | 1 |
6 files changed, 54 insertions, 183 deletions
diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php index bc921c0e..0ed4c67f 100644 --- a/framework/Web/Services/TPageService.php +++ b/framework/Web/Services/TPageService.php @@ -11,6 +11,10 @@ */
Prado::using('System.Web.UI.TPage');
+Prado::using('System.Web.UI.TTemplateManager');
+Prado::using('System.Web.UI.TThemeManager');
+Prado::using('System.Web.TAssetManager');
+
/**
* TPageService class.
*
@@ -63,6 +67,18 @@ class TPageService extends TComponent implements IService * @var TApplication application
*/
private $_application;
+ /**
+ * @var TAssetManager asset manager
+ */
+ private $_assetManager;
+ /**
+ * @var TThemeManager theme manager
+ */
+ private $_themeManager;
+ /**
+ * @var TTemplateManager template manager
+ */
+ private $_templateManager;
/**
* Initializes the service.
@@ -187,7 +203,15 @@ class TPageService extends TComponent implements IService */
public function getTemplateManager()
{
- return $this->_application->getModule('template');
+ return $this->_templateManager;
+ }
+
+ /**
+ * @param TTemplateManager template manager
+ */
+ public function setTemplateManager(TTemplateManager $value)
+ {
+ $this->_templateManager=$value;
}
/**
@@ -195,7 +219,15 @@ class TPageService extends TComponent implements IService */
public function getAssetManager()
{
- return $this->_application->getModule('asset');
+ return $this->_assetManager;
+ }
+
+ /**
+ * @param TAssetManager asset manager
+ */
+ public function setAssetManager(TAssetManager $value)
+ {
+ $this->_assetManager=$value;
}
/**
@@ -203,7 +235,15 @@ class TPageService extends TComponent implements IService */
public function getThemeManager()
{
- return $this->_application->getModule('theme');
+ return $this->_themeManager;
+ }
+
+ /**
+ * @param TThemeManager theme manager
+ */
+ public function setThemeManager(TThemeManager $value)
+ {
+ $this->_themeManager=$value;
}
/**
@@ -341,9 +381,9 @@ class TPageConfiguration extends TComponent * @var array list of module configurations
*/
private $_modules=array(
- 'template'=>array('System.Web.UI.TTemplateManager',array(),null),
- 'asset'=>array('System.Web.TAssetManager',array(),null),
- 'theme'=>array('System.Web.UI.TThemeManager',array(),null)
+ 'template'=>array('TTemplateManager',array(),null),
+ 'asset'=>array('TAssetManager',array(),null),
+ 'theme'=>array('TThemeManager',array(),null)
);
/**
* @var array list of parameters
diff --git a/framework/Web/TAssetManager.php b/framework/Web/TAssetManager.php index b5e1f6ec..f36714aa 100644 --- a/framework/Web/TAssetManager.php +++ b/framework/Web/TAssetManager.php @@ -71,6 +71,7 @@ class TAssetManager extends TComponent implements IModule throw new TConfigurationException('assetmanager_basepath_invalid',$this->_basePath);
if($this->_baseUrl===null)
$this->_baseUrl=dirname($application->getRequest()->getApplicationPath()).'/'.self::DEFAULT_BASEPATH;
+ $application->getService()->setAssetManager($this);
}
/**
diff --git a/framework/Web/UI/TTemplateControl.php b/framework/Web/UI/TTemplateControl.php index 19663002..13a3295f 100644 --- a/framework/Web/UI/TTemplateControl.php +++ b/framework/Web/UI/TTemplateControl.php @@ -11,11 +11,6 @@ */
/**
- * include TTemplate class file
- */
-require_once(PRADO_DIR.'/Web/UI/TTemplate.php');
-
-/**
* TTemplateControl class.
* TTemplateControl is the base class for all controls that use templates.
* By default, a control template is assumed to be in a file under the same
@@ -33,10 +28,6 @@ class TTemplateControl extends TControl implements INamingContainer * template file extension.
*/
const EXT_TEMPLATE='.tpl';
- /**
- * template cache file extension
- */
- const EXT_TEMPLATE_CACHE='.tpc';
/**
* @var ITemplate the parsed template structure shared by the same control class
diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php index 2703500a..d9d26c0a 100644 --- a/framework/Web/UI/TTemplateManager.php +++ b/framework/Web/UI/TTemplateManager.php @@ -1,5 +1,10 @@ <?php
+/**
+ * include TTemplate class file
+ */
+Prado::using('System.Web.UI.TTemplate');
+
class TTemplateManager extends TComponent implements IModule
{
const TEMPLATE_FILE_EXT='.tpl';
@@ -13,6 +18,7 @@ class TTemplateManager extends TComponent implements IModule public function init($application,$config)
{
$this->_application=$application;
+ $application->getService()->setTemplateManager($this);
}
/**
diff --git a/framework/Web/UI/TTheme.php b/framework/Web/UI/TTheme.php deleted file mode 100644 index 38aded50..00000000 --- a/framework/Web/UI/TTheme.php +++ /dev/null @@ -1,168 +0,0 @@ -<?php
-
-class TThemeManager extends TComponent implements IModule
-{
- const THEME_CACHE_PREFIX='prado:theme:';
- const DEFAULT_THEME_PATH='themes';
- const THEME_FILE='theme.tpl';
- /**
- * @var string module ID
- */
- private $_id;
- /**
- * @var boolean whether this module has been initialized
- */
- private $_initialized=false;
- /**
- * @var string the directory containing all themes
- */
- private $_themePath=null;
- /**
- * @var TApplication application
- */
- private $_application;
-
- /**
- * Initializes the module.
- * This method is required by IModule and is invoked by application.
- * @param TApplication application
- * @param TXmlElement module configuration
- */
- public function init($application,$config)
- {
- $this->_application=$application;
- if($this->_themePath===null)
- $this->_themePath=dirname($application->getConfigurationFile()).'/'.self::DEFAULT_THEME_PATH;
-
- $this->_initialized=true;
- }
-
- /**
- * @return string id of this module
- */
- public function getID()
- {
- return $this->_id;
- }
-
- /**
- * @param string id of this module
- */
- public function setID($value)
- {
- $this->_id=$value;
- }
-
- public function getTheme($name)
- {
- $themePath=realpath($this->_themePath.'/'.$name);
- if($themePath===false || !is_dir($this->_themePath))
- throw new TConfigurationException('thememanager_themepath_invalid',$themePath);
- if(($cache=$this->_application->getCache())===null)
- return new TTheme($themePath.'/'.self::THEME_FILE);
- else
- {
- $themeFile=$themePath.'/'.self::THEME_FILE;
- $array=$cache->get(self::THEME_CACHE_PREFIX.$themePath);
- if(is_array($array))
- {
- list($theme,$timestamp)=$array;
- if(filemtime($themeFile)<$timestamp)
- return $theme;
- }
- $theme=new TTheme($themeFile);
- $cache->set(self::THEME_CACHE_PREFIX.$themePath,array($theme,time()));
- return $theme;
- }
- }
-
- public function getThemePath()
- {
- return $this->_themePath;
- }
-
- public function setThemePath($value)
- {
- if($this->_initialized)
- throw new TInvalidOperationException('thememanager_themepath_unchangeable');
- else
- $this->_themePath=$value;
- }
-}
-
-class TTheme extends TTemplate
-{
- private $_themePath;
- private $_themeFile;
- private $_skins=array();
-
- public function __construct($themeFile)
- {
- $this->_themeFile=$themeFile;
- $this->_themePath=dirname($themeFile);
- if(is_file($themeFile) && is_readable($themeFile))
- {
- $theme=&$this->parse(file_get_contents($themeFile));
- foreach($theme as $skin)
- {
- if($skin[0]!==0)
- throw new TConfigurationException('theme_control_nested',$skin[1]);
- else if(!isset($skin[2])) // a text string, ignored
- continue;
- $type=$skin[1];
- $id=isset($skin[2]['skinid'])?$skin[2]['skinid']:0;
- unset($skin[2]['skinid']);
- if(isset($this->_skins[$type][$id]))
- throw new TConfigurationException('theme_skinid_duplicated',$type,$id);
- foreach($skin[2] as $name=>$value)
- {
- if(is_array($value) && $value[0]===0)
- throw new TConfigurationException('theme_databind_unsupported',$type,$id,$name);
- }
- $this->_skins[$type][$id]=$skin[2];
- }
- }
- else
- throw new TIOException('theme_themefile_invalid',$themeFile);
- }
-
- public function applySkin($control)
- {
- $type=get_class($control);
- if(($id=$control->getSkinID())==='')
- $id=0;
- if(isset($this->_skins[$type][$id]))
- {
- foreach($this->_skins[$type][$id] as $name=>$value)
- {
- if(is_array($value))
- $value=$this->evaluateExpression($value);
- if(strpos($name,'.')===false) // is simple property or custom attribute
- {
- if($control->hasProperty($name))
- {
- if($control->canSetProperty($name))
- {
- $setter='set'.$name;
- $control->$setter($value);
- }
- else
- throw new TConfigurationException('theme_property_readonly',get_class($control),$name);
- }
- else if($control->getAllowCustomAttributes())
- $control->getAttributes()->add($name,$value);
- else
- throw new TConfigurationException('theme_property_undefined',get_class($control),$name);
- }
- else // complex property
- $control->setSubProperty($name,$value);
- }
- return true;
- }
- else
- return false;
- }
-}
-
-
-?>
\ No newline at end of file diff --git a/framework/Web/UI/TThemeManager.php b/framework/Web/UI/TThemeManager.php index 9b407b90..9b7dc6a6 100644 --- a/framework/Web/UI/TThemeManager.php +++ b/framework/Web/UI/TThemeManager.php @@ -34,6 +34,7 @@ class TThemeManager extends TComponent implements IModule $this->_themePath=dirname($application->getRequest()->getPhysicalApplicationPath()).'/'.self::DEFAULT_THEME_PATH;
$this->_initialized=true;
+ $application->getService()->setThemeManager($this);
}
/**
|