Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
2809 rexy 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(
57
        'local'  => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
58
        'root'   => Smarty::SCOPE_ROOT, 'tpl_root' => Smarty::SCOPE_TPL_ROOT,
59
        'smarty' => Smarty::SCOPE_SMARTY, 'global' => Smarty::SCOPE_SMARTY
60
    );
61
 
62
    /**
63
     * Compiles code for the {config_load} tag
64
     *
65
     * @param array                                 $args     array with attributes from parser
66
     * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
67
     *
68
     * @return string compiled code
69
     * @throws \SmartyCompilerException
70
     */
71
    public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
72
    {
73
        // check and get attributes
74
        $_attr = $this->getAttributes($compiler, $args);
75
        if ($_attr[ 'nocache' ] === true) {
76
            $compiler->trigger_template_error('nocache option not allowed', null, true);
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
        // create config object
92
        $_output =
93
            "<?php\n\$_smarty_tpl->smarty->ext->configLoad->_loadConfigFile(\$_smarty_tpl, {$conf_file}, {$section}, {$_scope});\n?>\n";
94
        return $_output;
95
    }
96
}