1<?php
2/**
3 * Smarty Internal Plugin Compile Function Plugin
4 * Compiles code for the execution of function plugin
5 *
6 * @package    Smarty
7 * @subpackage Compiler
8 * @author     Uwe Tews
9 */
10
11/**
12 * Smarty Internal Plugin Compile Function Plugin Class
13 *
14 * @package    Smarty
15 * @subpackage Compiler
16 */
17class Smarty_Internal_Compile_Private_Function_Plugin 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();
26
27    /**
28     * Attribute definition: Overwrites base class.
29     *
30     * @var array
31     * @see Smarty_Internal_CompileBase
32     */
33    public $optional_attributes = array('_any');
34
35    /**
36     * Compiles code for the execution of function plugin
37     *
38     * @param array                                 $args      array with attributes from parser
39     * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object
40     * @param array                                 $parameter array with compilation parameter
41     * @param string                                $tag       name of function plugin
42     * @param string                                $function  PHP function name
43     *
44     * @return string compiled code
45     * @throws \SmartyCompilerException
46     * @throws \SmartyException
47     */
48    public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function)
49    {
50        // check and get attributes
51        $_attr = $this->getAttributes($compiler, $args);
52        unset($_attr[ 'nocache' ]);
53        // convert attributes into parameter array string
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        // compile code
64        $output = "{$function}({$_params},\$_smarty_tpl)";
65        if (!empty($parameter[ 'modifierlist' ])) {
66            $output = $compiler->compileTag(
67                'private_modifier',
68                array(),
69                array(
70                    'modifierlist' => $parameter[ 'modifierlist' ],
71                    'value'        => $output
72                )
73            );
74        }
75        $output = "<?php echo {$output};?>\n";
76        return $output;
77    }
78}
79