|
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 * Attribute definition: Overwrites base class. |
|
20 * |
|
21 * @var array |
|
22 * @see Smarty_Internal_CompileBase |
|
23 */ |
|
24 public $optional_attributes = array('_any'); |
|
25 |
|
26 /** |
|
27 * Compiles code for the execution of function plugin |
|
28 * |
|
29 * @param array $args array with attributes from parser |
|
30 * @param object $compiler compiler object |
|
31 * @param array $parameter array with compilation parameter |
|
32 * @param string $tag name of function |
|
33 * @param string $method name of method to call |
|
34 * |
|
35 * @return string compiled code |
|
36 */ |
|
37 public function compile($args, $compiler, $parameter, $tag, $method) { |
|
38 // check and get attributes |
|
39 $_attr = $this->getAttributes($compiler, $args); |
|
40 if ($_attr['nocache'] === true) { |
|
41 $compiler->tag_nocache = true; |
|
42 } |
|
43 unset($_attr['nocache']); |
|
44 $_assign = null; |
|
45 if (isset($_attr['assign'])) { |
|
46 $_assign = $_attr['assign']; |
|
47 unset($_attr['assign']); |
|
48 } |
|
49 // method or property ? |
|
50 if (method_exists($compiler->smarty->registered_objects[$tag][0], $method)) { |
|
51 // convert attributes into parameter array string |
|
52 if ($compiler->smarty->registered_objects[$tag][2]) { |
|
53 $_paramsArray = array(); |
|
54 foreach ($_attr as $_key => $_value) { |
|
55 if (is_int($_key)) { |
|
56 $_paramsArray[] = "$_key=>$_value"; |
|
57 } else { |
|
58 $_paramsArray[] = "'$_key'=>$_value"; |
|
59 } |
|
60 } |
|
61 $_params = 'array(' . implode(",", $_paramsArray) . ')'; |
|
62 $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params},\$_smarty_tpl)"; |
|
63 } else { |
|
64 $_params = implode(",", $_attr); |
|
65 $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params})"; |
|
66 } |
|
67 } else { |
|
68 // object property |
|
69 $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}"; |
|
70 } |
|
71 |
|
72 if (empty($_assign)) { |
|
73 // This tag does create output |
|
74 $compiler->has_output = true; |
|
75 $output = "<?php echo {$return};?>\n"; |
|
76 } else { |
|
77 $output = "<?php \$_smarty_tpl->assign({$_assign},{$return});?>\n"; |
|
78 } |
|
79 |
|
80 return $output; |
|
81 } |
|
82 } |