3 * Smarty Resource Plugin
6 * @subpackage TemplateResources
11 * Smarty Resource Plugin
13 * Wrapper Implementation for custom resource plugins
16 * @subpackage TemplateResources
18 abstract class Smarty_Resource_Custom extends Smarty_Resource {
21 * fetch template and its modification time from data source
23 * @param string $name template name
24 * @param string &$source template source
25 * @param integer &$mtime template modification timestamp (epoch)
27 protected abstract function fetch($name, &$source, &$mtime);
30 * Fetch template's modification timestamp from data source
32 * {@internal implementing this method is optional.
33 * Only implement it if modification times can be accessed faster than loading the complete template source.}}
35 * @param string $name template name
36 * @return integer|boolean timestamp (epoch) the template was modified, or false if not found
38 protected function fetchTimestamp($name)
44 * populate Source Object with meta data from Resource
46 * @param Smarty_Template_Source $source source object
47 * @param Smarty_Internal_Template $_template template object
49 public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template=null)
51 $source->filepath = strtolower($source->type . ':' . $source->name);
52 $source->uid = sha1($source->type . ':' . $source->name);
54 $mtime = $this->fetchTimestamp($source->name);
55 if ($mtime !== null) {
56 $source->timestamp = $mtime;
58 $this->fetch($source->name, $content, $timestamp);
59 $source->timestamp = isset($timestamp) ? $timestamp : false;
61 $source->content = $content;
63 $source->exists = !!$source->timestamp;
67 * Load template's source into current template object
69 * @param Smarty_Template_Source $source source object
70 * @return string template source
71 * @throws SmartyException if source cannot be loaded
73 public function getContent(Smarty_Template_Source $source)
75 $this->fetch($source->name, $content, $timestamp);
76 if (isset($content)) {
80 throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
84 * Determine basename for compiled filename
86 * @param Smarty_Template_Source $source source object
87 * @return string resource's basename
89 protected function getBasename(Smarty_Template_Source $source)
91 return basename($source->name);