3 * Smarty Resource Extension
6 * @subpackage TemplateResources
11 * Smarty Resource Extension
12 * Default template and config file handling
15 * @subpackage TemplateResources
17 class Smarty_Internal_Extension_DefaultTemplateHandler
21 * get default content from template of config resource handler
23 * @param Smarty_Internal_Template $_template
24 * @param Smarty_Internal_Template_Source $source
25 * @param Smarty_Resource $resObj
27 static function _getDefault(Smarty_Internal_Template
$_template, &$source, &$resObj)
29 if ($source->isConfig
) {
30 $default_handler = $_template->smarty
->default_config_handler_func
;
32 $default_handler = $_template->smarty
->default_template_handler_func
;
34 $_content = $_timestamp = null;
35 $_return = call_user_func_array($default_handler,
36 array($source->type
, $source->name
, &$_content, &$_timestamp, $source->smarty
));
37 if (is_string($_return)) {
38 $source->exists
= is_file($_return);
39 if ($source->exists
) {
40 $source->timestamp
= filemtime($_return);
42 $source->filepath
= $_return;
43 } elseif ($_return === true) {
44 $source->content
= $_content;
45 $source->timestamp
= $_timestamp;
46 $source->exists
= true;
47 $source->recompiled
= true;
48 $source->filepath
= false;
53 * register template default handler
55 * @param Smarty $smarty
56 * @param mixed $callback
58 * @throws SmartyException
60 static function registerDefaultTemplateHandler(Smarty
$smarty, $callback)
62 if (is_callable($callback)) {
63 $smarty->default_template_handler_func
= $callback;
65 throw new SmartyException("Default template handler not callable");
70 * register config default handler
72 * @param Smarty $smarty
73 * @param mixed $callback
75 * @throws SmartyException
77 static function registerDefaultConfigHandler(Smarty
$smarty, $callback)
79 if (is_callable($callback)) {
80 $smarty->default_config_handler_func
= $callback;
82 throw new SmartyException("Default config handler not callable");