|
1 <?php |
|
2 /** |
|
3 * Smarty Resource Extension |
|
4 * |
|
5 * @package Smarty |
|
6 * @subpackage TemplateResources |
|
7 * @author Uwe Tews |
|
8 */ |
|
9 |
|
10 /** |
|
11 * Smarty Resource Extension |
|
12 * Default template and config file handling |
|
13 * |
|
14 * @package Smarty |
|
15 * @subpackage TemplateResources |
|
16 */ |
|
17 class Smarty_Internal_Extension_DefaultTemplateHandler { |
|
18 |
|
19 /** |
|
20 * get default content from template of config resource handler |
|
21 * |
|
22 * @param Smarty_Internal_Template $_template |
|
23 * @param Smarty_Internal_Template_Source $source |
|
24 * @param Smarty_Resource $resObj |
|
25 */ |
|
26 static function _getDefault(Smarty_Internal_Template $_template, &$source, &$resObj) { |
|
27 if ($source->isConfig) { |
|
28 $default_handler = $_template->smarty->default_config_handler_func; |
|
29 } else { |
|
30 $default_handler = $_template->smarty->default_template_handler_func; |
|
31 } |
|
32 $_content = $_timestamp = null; |
|
33 $_return = call_user_func_array($default_handler, |
|
34 array($source->type, $source->name, &$_content, &$_timestamp, $source->smarty)); |
|
35 if (is_string($_return)) { |
|
36 $source->exists = is_file($_return); |
|
37 if ($source->exists) { |
|
38 $source->timestamp = filemtime($_return); |
|
39 } |
|
40 $source->filepath = $_return; |
|
41 } elseif ($_return === true) { |
|
42 $source->content = $_content; |
|
43 $source->timestamp = $_timestamp; |
|
44 $source->exists = true; |
|
45 $source->recompiled = true; |
|
46 $source->filepath = false; |
|
47 } |
|
48 } |
|
49 |
|
50 /** |
|
51 * register template default handler |
|
52 * |
|
53 * @param Smarty $smarty |
|
54 * @param mixed $callback |
|
55 * |
|
56 * @throws SmartyException |
|
57 */ |
|
58 static function registerDefaultTemplateHandler(Smarty $smarty, $callback) { |
|
59 if (is_callable($callback)) { |
|
60 $smarty->default_template_handler_func = $callback; |
|
61 } else { |
|
62 throw new SmartyException("Default template handler not callable"); |
|
63 } |
|
64 } |
|
65 |
|
66 /** |
|
67 * register config default handler |
|
68 * |
|
69 * @param Smarty $smarty |
|
70 * @param mixed $callback |
|
71 * |
|
72 * @throws SmartyException |
|
73 */ |
|
74 static function registerDefaultConfigHandler(Smarty $smarty, $callback) { |
|
75 if (is_callable($callback)) { |
|
76 $smarty->default_config_handler_func = $callback; |
|
77 } else { |
|
78 throw new SmartyException("Default config handler not callable"); |
|
79 } |
|
80 } |
|
81 } |