]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_template_config.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_template_config.php
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  */
19 class Smarty_Template_Config extends Smarty_Template_Source
20 {
21     /**
22      * array of section names, single section or null
23      *
24      * @var null|string|array
25      */
26     public $config_sections = null;
27
28     /**
29      * scope into which the config variables shall be loaded
30      *
31      * @var int
32      */
33     public $scope = 0;
34
35     /**
36      * Flag that source is a config file
37      *
38      * @var bool
39      */
40     public $isConfig = true;
41
42     /**
43      * Name of the Class to compile this resource's contents with
44      *
45      * @var string
46      */
47     public $compiler_class = 'Smarty_Internal_Config_File_Compiler';
48
49     /**
50      * Name of the Class to tokenize this resource's contents with
51      *
52      * @var string
53      */
54     public $template_lexer_class = 'Smarty_Internal_Configfilelexer';
55
56     /**
57      * Name of the Class to parse this resource's contents with
58      *
59      * @var string
60      */
61     public $template_parser_class = 'Smarty_Internal_Configfileparser';
62
63     /**
64      * initialize Source Object for given resource
65      * Either [$_template] or [$smarty, $template_resource] must be specified
66      *
67      * @param  Smarty_Internal_Template $_template         template object
68      * @param  Smarty                   $smarty            smarty object
69      * @param  string                   $template_resource resource identifier
70      *
71      * @return Smarty_Template_Config Source Object
72      * @throws SmartyException
73      */
74     public static function load(Smarty_Internal_Template $_template = null, Smarty $smarty = null,
75                                 $template_resource = null)
76     {
77         static $_incompatible_resources = array('extends' => true, 'php' => true);
78         if ($_template) {
79             $smarty = $_template->smarty;
80             $template_resource = $_template->template_resource;
81         }
82         if (empty($template_resource)) {
83             throw new SmartyException('Source: Missing  name');
84         }
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");
90         }
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);
96         }
97         return $source;
98     }
99 }