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

Smarty_Internal_Compile_Config_Load   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 82
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B compile() 0 29 4
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