3 * Smarty Internal Plugin Resource Registered
6 * @subpackage TemplateResources
12 * Smarty Internal Plugin Resource Registered
13 * Implements the registered resource for Smarty template
16 * @subpackage TemplateResources
19 class Smarty_Internal_Resource_Registered extends Smarty_Resource
22 * populate Source Object with meta data from Resource
24 * @param Smarty_Template_Source $source source object
25 * @param Smarty_Internal_Template $_template template object
29 public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
31 $source->filepath = $source->type . ':' . $source->name;
32 $source->uid = sha1($source->filepath);
33 if ($source->smarty->compile_check) {
34 $source->timestamp = $this->getTemplateTimestamp($source);
35 $source->exists = !!$source->timestamp;
40 * populate Source Object with timestamp and exists from Resource
42 * @param Smarty_Template_Source $source source object
46 public function populateTimestamp(Smarty_Template_Source $source)
48 $source->timestamp = $this->getTemplateTimestamp($source);
49 $source->exists = !!$source->timestamp;
53 * Get timestamp (epoch) the template source was modified
55 * @param Smarty_Template_Source $source source object
57 * @return integer|boolean timestamp (epoch) the template was modified, false if resources has no timestamp
59 public function getTemplateTimestamp(Smarty_Template_Source $source)
63 call_user_func_array($source->smarty->registered_resources[$source->type][0][1], array($source->name, &$time_stamp, $source->smarty));
65 return is_numeric($time_stamp) ? (int) $time_stamp : $time_stamp;
69 * Load template's source by invoking the registered callback into current template object
71 * @param Smarty_Template_Source $source source object
73 * @return string template source
74 * @throws SmartyException if source cannot be loaded
76 public function getContent(Smarty_Template_Source $source)
78 // return template string
79 $t = call_user_func_array($source->smarty->registered_resources[$source->type][0][0], array($source->name, &$source->content, $source->smarty));
80 if (is_bool($t) && !$t) {
81 throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
84 return $source->content;
88 * Determine basename for compiled filename
90 * @param Smarty_Template_Source $source source object
92 * @return string resource's basename
94 protected function getBasename(Smarty_Template_Source $source)
96 return basename($source->name);