Completed
Branch master (e379bd)
by Pierre-Henry
33:06
created

Smarty_Internal_Compile_Config_Load::compile()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 16
nc 8
nop 2
dl 0
loc 29
rs 8.5806
c 0
b 0
f 0
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
}
99