3 * Smarty Config Source Plugin
6 * @subpackage TemplateResources
11 * Smarty Config Resource Data Object
12 * Meta Data Container for Template Files
15 * @subpackage TemplateResources
19 class Smarty_Template_Config extends Smarty_Template_Source
22 * array of section names, single section or null
24 * @var null|string|array
26 public $config_sections = null;
29 * scope into which the config variables shall be loaded
36 * Flag that source is a config file
40 public $isConfig = true;
43 * Name of the Class to compile this resource's contents with
47 public $compiler_class = 'Smarty_Internal_Config_File_Compiler';
50 * Name of the Class to tokenize this resource's contents with
54 public $template_lexer_class = 'Smarty_Internal_Configfilelexer';
57 * Name of the Class to parse this resource's contents with
61 public $template_parser_class = 'Smarty_Internal_Configfileparser';
64 * initialize Source Object for given resource
65 * Either [$_template] or [$smarty, $template_resource] must be specified
67 * @param Smarty_Internal_Template $_template template object
68 * @param Smarty $smarty smarty object
69 * @param string $template_resource resource identifier
71 * @return Smarty_Template_Config Source Object
72 * @throws SmartyException
74 public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null,
75 $template_resource = null)
77 static $_incompatible_resources = array('extends' => true, 'php' => true);
79 $smarty = $_template->smarty;
80 $template_resource = $_template->template_resource;
82 if (empty($template_resource)) {
83 throw new SmartyException('Source: Missing name');
85 // parse resource_name, load resource handler
86 list($name, $type) = Smarty_Resource::parseResourceName($template_resource, $smarty->default_config_type);
87 // make sure configs are not loaded via anything smarty can't handle
88 if (isset($_incompatible_resources[ $type ])) {
89 throw new SmartyException ("Unable to use resource '{$type}' for config");
91 $source = new Smarty_Template_Config($smarty, $template_resource, $type, $name);
92 $source->handler->populate($source, $_template);
93 if (!$source->exists && isset($smarty->default_config_handler_func)) {
94 Smarty_Internal_Method_RegisterDefaultTemplateHandler::_getDefaultTemplate($source);
95 $source->handler->populate($source, $_template);