diff options
author | xue <> | 2005-11-10 12:47:19 +0000 |
---|---|---|
committer | xue <> | 2005-11-10 12:47:19 +0000 |
commit | 55c4ac1bfe565f1ca7f537fdd8b7a201be28e581 (patch) | |
tree | a0599d5e36fdbb3f1e169ae56bab7d529597e3eb /framework/Web/UI/TTemplateManager.php |
Initial import of prado framework
Diffstat (limited to 'framework/Web/UI/TTemplateManager.php')
-rw-r--r-- | framework/Web/UI/TTemplateManager.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/framework/Web/UI/TTemplateManager.php b/framework/Web/UI/TTemplateManager.php new file mode 100644 index 00000000..2f8ae688 --- /dev/null +++ b/framework/Web/UI/TTemplateManager.php @@ -0,0 +1,66 @@ +<?php
+
+class TTemplateManager extends TComponent implements IModule
+{
+ const TEMPLATE_FILE_EXT='.tpl';
+ const TEMPLATE_CACHE_PREFIX='prado:template:';
+ private $_application;
+ /**
+ * @var string module ID
+ */
+ private $_id;
+
+ public function init($application,$config)
+ {
+ $this->_application=$application;
+ }
+
+ /**
+ * @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 loadTemplateByClassName($className)
+ {
+ $class=new ReflectionClass($className);
+ $tplFile=dirname($class->getFileName()).'/'.$className.self::TEMPLATE_FILE_EXT;
+ return $this->loadTemplateByFileName($tplFile);
+ }
+
+ public function loadTemplateByFileName($fileName)
+ {
+ if(is_file($fileName))
+ {
+ if(($cache=$this->_application->getCache())===null)
+ return new TTemplate(file_get_contents($fileName));
+ else
+ {
+ $array=$cache->get(self::TEMPLATE_CACHE_PREFIX.$fileName);
+ if(is_array($array))
+ {
+ list($template,$timestamp)=$array;
+ if(filemtime($fileName)<$timestamp)
+ return $template;
+ }
+ $template=new TTemplate(file_get_contents($fileName));
+ $cache->set(self::TEMPLATE_CACHE_PREFIX.$fileName,array($template,time()));
+ return $template;
+ }
+ }
+ else
+ return null;
+ }
+}
+
+?>
\ No newline at end of file |