3 * Smarty Internal Plugin Resource File
6 * @subpackage TemplateResources
12 * Smarty Internal Plugin Resource File
13 * Implements the file system as resource for Smarty templates
16 * @subpackage TemplateResources
18 class Smarty_Internal_Resource_File extends Smarty_Resource
21 * populate Source Object with meta data from Resource
23 * @param Smarty_Template_Source $source source object
24 * @param Smarty_Internal_Template $_template template object
26 public function populate(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
28 $source->filepath = $this->buildFilepath($source, $_template);
30 if ($source->filepath !== false) {
31 if (is_object($source->smarty->security_policy)) {
32 $source->smarty->security_policy->isTrustedResourceDir($source->filepath);
35 $source->uid = sha1(realpath($source->filepath));
36 if ($source->smarty->compile_check && !isset($source->timestamp)) {
37 $source->timestamp = @filemtime($source->filepath);
38 $source->exists = !!$source->timestamp;
44 * populate Source Object with timestamp and exists from Resource
46 * @param Smarty_Template_Source $source source object
48 public function populateTimestamp(Smarty_Template_Source $source)
50 $source->timestamp = @filemtime($source->filepath);
51 $source->exists = !!$source->timestamp;
55 * Load template's source from file into current template object
57 * @param Smarty_Template_Source $source source object
59 * @return string template source
60 * @throws SmartyException if source cannot be loaded
62 public function getContent(Smarty_Template_Source $source)
64 if ($source->timestamp) {
65 return file_get_contents($source->filepath);
67 if ($source instanceof Smarty_Config_Source) {
68 throw new SmartyException("Unable to read config {$source->type} '{$source->name}'");
70 throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
74 * Determine basename for compiled filename
76 * @param Smarty_Template_Source $source source object
78 * @return string resource's basename
80 public function getBasename(Smarty_Template_Source $source)
82 $_file = $source->name;
83 if (($_pos = strpos($_file, ']')) !== false) {
84 $_file = substr($_file, $_pos + 1);
87 return basename($_file);