Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
2809 rexy 1
<?php
2
/**
3
 * Smarty Internal Plugin Compile Object Function
4
 * Compiles code for registered objects as function
5
 *
6
 * @package    Smarty
7
 * @subpackage Compiler
8
 * @author     Uwe Tews
9
 */
10
 
11
/**
12
 * Smarty Internal Plugin Compile Object Function Class
13
 *
14
 * @package    Smarty
15
 * @subpackage Compiler
16
 */
17
class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_CompileBase
18
{
19
    /**
20
     * Attribute definition: Overwrites base class.
21
     *
22
     * @var array
23
     * @see Smarty_Internal_CompileBase
24
     */
25
    public $optional_attributes = array('_any');
26
 
27
    /**
28
     * Compiles code for the execution of function plugin
29
     *
30
     * @param array                                 $args      array with attributes from parser
31
     * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object
32
     * @param array                                 $parameter array with compilation parameter
33
     * @param string                                $tag       name of function
34
     * @param string                                $method    name of method to call
35
     *
36
     * @return string compiled code
37
     * @throws \SmartyCompilerException
38
     * @throws \SmartyException
39
     */
40
    public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method)
41
    {
42
        // check and get attributes
43
        $_attr = $this->getAttributes($compiler, $args);
44
        unset($_attr[ 'nocache' ]);
45
        $_assign = null;
46
        if (isset($_attr[ 'assign' ])) {
47
            $_assign = $_attr[ 'assign' ];
48
            unset($_attr[ 'assign' ]);
49
        }
50
        // method or property ?
51
        if (is_callable(array($compiler->smarty->registered_objects[ $tag ][ 0 ], $method))) {
52
            // convert attributes into parameter array string
53
            if ($compiler->smarty->registered_objects[ $tag ][ 2 ]) {
54
                $_paramsArray = array();
55
                foreach ($_attr as $_key => $_value) {
56
                    if (is_int($_key)) {
57
                        $_paramsArray[] = "$_key=>$_value";
58
                    } else {
59
                        $_paramsArray[] = "'$_key'=>$_value";
60
                    }
61
                }
62
                $_params = 'array(' . implode(',', $_paramsArray) . ')';
63
                $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params},\$_smarty_tpl)";
64
            } else {
65
                $_params = implode(',', $_attr);
66
                $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params})";
67
            }
68
        } else {
69
            // object property
70
            $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}";
71
        }
72
        if (!empty($parameter[ 'modifierlist' ])) {
73
            $output = $compiler->compileTag(
74
                'private_modifier',
75
                array(),
76
                array('modifierlist' => $parameter[ 'modifierlist' ], 'value' => $output)
77
            );
78
        }
79
        if (empty($_assign)) {
80
            return "<?php echo {$output};?>\n";
81
        } else {
82
            return "<?php \$_smarty_tpl->assign({$_assign},{$output});?>\n";
83
        }
84
    }
85
}