3 * Smarty Internal Plugin Resource Extends
6 * @subpackage TemplateResources
12 * Smarty Internal Plugin Resource Extends
13 * Implements the file system as resource for Smarty which {extend}s a chain of template files templates
16 * @subpackage TemplateResources
18 class Smarty_Internal_Resource_Extends
extends Smarty_Resource
21 * mbstring.overload flag
25 public $mbstring_overload = 0;
28 * populate Source Object with meta data from Resource
30 * @param Smarty_Template_Source $source source object
31 * @param Smarty_Internal_Template $_template template object
33 * @throws SmartyException
35 public function populate(Smarty_Template_Source
$source, Smarty_Internal_Template
$_template = null)
37 $uid = sha1(getcwd());
39 $components = explode('|', $source->name
);
41 foreach ($components as $component) {
42 $s = Smarty_Resource
::source(null, $source->smarty
, $component);
43 if ($s->type
== 'php') {
44 throw new SmartyException("Resource type {$s->type} cannot be used with the extends resource type");
46 $sources[$s->uid
] = $s;
47 $uid .= realpath($s->filepath
);
48 if ($_template && $_template->smarty
->compile_check
) {
49 $exists = $exists && $s->exists
;
52 $source->components
= $sources;
53 $source->filepath
= $s->filepath
;
54 $source->uid
= sha1($uid);
55 if ($_template && $_template->smarty
->compile_check
) {
56 $source->timestamp
= $s->timestamp
;
57 $source->exists
= $exists;
59 // need the template at getContent()
60 $source->template
= $_template;
64 * populate Source Object with timestamp and exists from Resource
66 * @param Smarty_Template_Source $source source object
68 public function populateTimestamp(Smarty_Template_Source
$source)
70 $source->exists
= true;
71 foreach ($source->components
as $s) {
72 $source->exists
= $source->exists
&& $s->exists
;
74 $source->timestamp
= $s->timestamp
;
78 * Load template's source from files into current template object
80 * @param Smarty_Template_Source $source source object
82 * @return string template source
83 * @throws SmartyException if source cannot be loaded
85 public function getContent(Smarty_Template_Source
$source)
87 if (!$source->exists
) {
88 throw new SmartyException("Unable to read template {$source->type} '{$source->name}'");
91 $_components = array_reverse($source->components
);
94 foreach ($_components as $_component) {
96 $_content .= $_component->content
;
102 * Determine basename for compiled filename
104 * @param Smarty_Template_Source $source source object
106 * @return string resource's basename
108 public function getBasename(Smarty_Template_Source
$source)
110 return str_replace(':', '.', basename($source->filepath
));