33 * Smarty Internal Plugin Compile Registered Function
44 * Compiles code for the execution of a registered function
55 *
6-
7-
86 * @author Uwe Tews
97 */
108
119namespace Smarty \Compile ;
1210
1311use Smarty \Compiler \Template ;
14- use Smarty \CompilerException ;
1512
1613/**
1714 * Smarty Internal Plugin Compile Registered Function Class
18- *
19-
20-
2115 */
2216class FunctionCallCompiler extends Base {
23-
24- /**
25- * Attribute definition: Overwrites base class.
26- *
27- * @var array
28- * @see BasePlugin
29- */
30- public $ optional_attributes = ['_any ' ];
31-
32- /**
33- * Shorttag attribute order defined by its names
34- *
35- * @var array
36- */
37- protected $ shorttag_order = [];
38-
3917 /**
4018 * Compiles code for the execution of a registered function
4119 *
@@ -51,14 +29,8 @@ class FunctionCallCompiler extends Base {
5129 */
5230 public function compile ($ args , Template $ compiler , $ parameter = [], $ tag = null , $ function = null ): string
5331 {
54-
55- // check and get attributes
56- $ _attr = $ this ->getAttributes ($ compiler , $ args );
57- unset($ _attr ['nocache ' ]);
58-
59- $ _paramsArray = $ this ->formatParamsArray ($ _attr );
60- $ _params = 'array( ' . implode (', ' , $ _paramsArray ) . ') ' ;
61-
32+ // Compile arguments to pass on the the functionhandler
33+ $ _params = $ this ->compileArguments ($ args );
6234
6335 if ($ functionHandler = $ compiler ->getSmarty ()->getFunctionHandler ($ function )) {
6436
@@ -76,4 +48,27 @@ public function compile($args, Template $compiler, $parameter = [], $tag = null,
7648
7749 return $ output ;
7850 }
51+
52+ /**
53+ * Recursively compile function arguments.
54+ * @param array $args array with attributes from parser
55+ * @return string compiled arguments
56+ */
57+ private function compileArguments (array $ arguments ): string
58+ {
59+ $ params = '' ;
60+
61+ foreach ($ arguments as $ key => $ value ) {
62+ $ params .= var_export ($ key , true ) . "=> " ;
63+ if (is_array ($ value )) {
64+ $ params .= $ this ->compileArguments ($ value );
65+ } else {
66+ $ params .= $ value ;
67+ }
68+
69+ $ params .= ', ' ;
70+ }
71+
72+ return '[ ' . rtrim ($ params , ', ' ) . '] ' ;
73+ }
7974}
0 commit comments