Smarty_Internal_Compile_Eval   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 52
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A compile() 0 18 3
1
<?php
2
/**
3
 * Smarty Internal Plugin Compile Eval
4
 * Compiles the {eval} tag.
5
 *
6
 * @package    Smarty
7
 * @subpackage Compiler
8
 * @author     Uwe Tews
9
 */
10
11
/**
12
 * Smarty Internal Plugin Compile Eval Class
13
 *
14
 * @package    Smarty
15
 * @subpackage Compiler
16
 */
17
class Smarty_Internal_Compile_Eval 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('var');
26
27
    /**
28
     * Attribute definition: Overwrites base class.
29
     *
30
     * @var array
31
     * @see Smarty_Internal_CompileBase
32
     */
33
    public $optional_attributes = array('assign');
34
35
    /**
36
     * Attribute definition: Overwrites base class.
37
     *
38
     * @var array
39
     * @see Smarty_Internal_CompileBase
40
     */
41
    public $shorttag_order = array('var', 'assign');
42
43
    /**
44
     * Compiles code for the {eval} tag
45
     *
46
     * @param array  $args     array with attributes from parser
47
     * @param object $compiler compiler object
48
     *
49
     * @return string compiled code
50
     */
51
    public function compile($args, $compiler)
52
    {
53
        // check and get attributes
54
        $_attr = $this->getAttributes($compiler, $args);
55
        if (isset($_attr[ 'assign' ])) {
56
            // output will be stored in a smarty variable instead of being displayed
57
            $_assign = $_attr[ 'assign' ];
58
        }
59
        // create template object
60
        $_output =
61
            "\$_template = new {$compiler->smarty->template_class}('eval:'.{$_attr[ 'var' ]}, \$_smarty_tpl->smarty, \$_smarty_tpl);";
62
        //was there an assign attribute?
63
        if (isset($_assign)) {
64
            $_output .= "\$_smarty_tpl->assign($_assign,\$_template->fetch());";
65
        } else {
66
            $_output .= 'echo $_template->fetch();';
67
        }
68
        return "<?php $_output ?>";
69
    }
70
}
71