1: <?php
2: /**
3: * Smarty Config Source Plugin
4: *
5: * @package Smarty
6: * @subpackage TemplateResources
7: * @author Uwe Tews
8: */
9:
10: /**
11: * Smarty Config Resource Data Object
12: * Meta Data Container for Template Files
13: *
14: * @package Smarty
15: * @subpackage TemplateResources
16: * @author Uwe Tews
17: */
18: class Smarty_Template_Config extends Smarty_Template_Source
19: {
20: /**
21: * array of section names, single section or null
22: *
23: * @var null|string|array
24: */
25: public $config_sections = null;
26:
27: /**
28: * scope into which the config variables shall be loaded
29: *
30: * @var int
31: */
32: public $scope = 0;
33:
34: /**
35: * Flag that source is a config file
36: *
37: * @var bool
38: */
39: public $isConfig = true;
40:
41: /**
42: * Name of the Class to compile this resource's contents with
43: *
44: * @var string
45: */
46: public $compiler_class = 'Smarty_Internal_Config_File_Compiler';
47:
48: /**
49: * Name of the Class to tokenize this resource's contents with
50: *
51: * @var string
52: */
53: public $template_lexer_class = 'Smarty_Internal_Configfilelexer';
54:
55: /**
56: * Name of the Class to parse this resource's contents with
57: *
58: * @var string
59: */
60: public $template_parser_class = 'Smarty_Internal_Configfileparser';
61:
62: /**
63: * initialize Source Object for given resource
64: * Either [$_template] or [$smarty, $template_resource] must be specified
65: *
66: * @param Smarty_Internal_Template $_template template object
67: * @param Smarty $smarty smarty object
68: * @param string $template_resource resource identifier
69: *
70: * @return Smarty_Template_Config Source Object
71: * @throws SmartyException
72: */
73: public static function load(
74: Smarty_Internal_Template $_template = null,
75: Smarty $smarty = null,
76: $template_resource = null
77: ) {
78: static $_incompatible_resources = array('extends' => true, 'php' => true);
79: if ($_template) {
80: $smarty = $_template->smarty;
81: $template_resource = $_template->template_resource;
82: }
83: if (empty($template_resource)) {
84: throw new SmartyException('Source: Missing name');
85: }
86: // parse resource_name, load resource handler
87: list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $smarty->default_config_type);
88: // make sure configs are not loaded via anything smarty can't handle
89: if (isset($_incompatible_resources[ $type ])) {
90: throw new SmartyException("Unable to use resource '{$type}' for config");
91: }
92: $source = new Smarty_Template_Config($smarty, $template_resource, $type, $name);
93: $source->handler->populate($source, $_template);
94: if (!$source->exists && isset($smarty->default_config_handler_func)) {
95: Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
96: $source->handler->populate($source, $_template);
97: }
98: return $source;
99: }
100: }
101: