]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_config_load.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_compile_config_load.php
1 <?php
2 /**
3  * Smarty Internal Plugin Compile Config Load
4  * Compiles the {config load} tag
5  *
6  * @package    Smarty
7  * @subpackage Compiler
8  * @author     Uwe Tews
9  */
10
11 /**
12  * Smarty Internal Plugin Compile Config Load Class
13  *
14  * @package    Smarty
15  * @subpackage Compiler
16  */
17 class Smarty_Internal_Compile_Config_Load extends Smarty_Internal_CompileBase
18 {
19     /**
20      * Attribute definition: Overwrites base class.
21      *
22      * @var array
23      * @see Smarty_Internal_CompileBase
24      */
25     public $required_attributes = array('file');
26
27     /**
28      * Attribute definition: Overwrites base class.
29      *
30      * @var array
31      * @see Smarty_Internal_CompileBase
32      */
33     public $shorttag_order = array('file', 'section');
34
35     /**
36      * Attribute definition: Overwrites base class.
37      *
38      * @var array
39      * @see Smarty_Internal_CompileBase
40      */
41     public $optional_attributes = array('section', 'scope');
42
43     /**
44      * Attribute definition: Overwrites base class.
45      *
46      * @var array
47      * @see Smarty_Internal_CompileBase
48      */
49     public $option_flags = array('nocache', 'noscope');
50
51     /**
52      * Valid scope names
53      *
54      * @var array
55      */
56     public $valid_scopes = array('local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
57                                  'root' => Smarty::SCOPE_ROOT, 'tpl_root' => Smarty::SCOPE_TPL_ROOT,
58                                  'smarty' => Smarty::SCOPE_SMARTY, 'global' => Smarty::SCOPE_SMARTY);
59
60     /**
61      * Compiles code for the {config_load} tag
62      *
63      * @param  array                                $args     array with attributes from parser
64      * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
65      *
66      * @return string compiled code
67      * @throws \SmartyCompilerException
68      */
69     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
70     {
71         // check and get attributes
72         $_attr = $this->getAttributes($compiler, $args);
73
74         if ($_attr[ 'nocache' ] === true) {
75             $compiler->trigger_template_error('nocache option not allowed', null, true);
76         }
77
78         // save possible attributes
79         $conf_file = $_attr[ 'file' ];
80         if (isset($_attr[ 'section' ])) {
81             $section = $_attr[ 'section' ];
82         } else {
83             $section = 'null';
84         }
85         // scope setup
86         if ($_attr[ 'noscope' ]) {
87             $_scope = - 1;
88         } else {
89             $_scope = $compiler->convertScope($_attr, $this->valid_scopes);
90         }
91
92         // create config object
93         $_output =
94             "<?php\n\$_smarty_tpl->smarty->ext->configLoad->_loadConfigFile(\$_smarty_tpl, {$conf_file}, {$section}, {$_scope});\n?>\n";
95
96         return $_output;
97     }
98 }