3 * Smarty Internal Plugin Compile Object Function
4 * Compiles code for registered objects as function
12 * Smarty Internal Plugin Compile Object Function Class
15 * @subpackage Compiler
17 class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_CompileBase
20 * Attribute definition: Overwrites base class.
23 * @see Smarty_Internal_CompileBase
25 public $optional_attributes = array('_any');
28 * Compiles code for the execution of function plugin
30 * @param array $args array with attributes from parser
31 * @param object $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
36 * @return string compiled code
38 public function compile($args, $compiler, $parameter, $tag, $method)
40 // check and get attributes
41 $_attr = $this->getAttributes($compiler, $args);
42 if ($_attr['nocache'] === true) {
43 $compiler->tag_nocache = true;
45 unset($_attr['nocache']);
47 if (isset($_attr['assign'])) {
48 $_assign = $_attr['assign'];
49 unset($_attr['assign']);
51 // method or property ?
52 if (method_exists($compiler->smarty->registered_objects[$tag][0], $method)) {
53 // convert attributes into parameter array string
54 if ($compiler->smarty->registered_objects[$tag][2]) {
55 $_paramsArray = array();
56 foreach ($_attr as $_key => $_value) {
58 $_paramsArray[] = "$_key=>$_value";
60 $_paramsArray[] = "'$_key'=>$_value";
63 $_params = 'array(' . implode(",", $_paramsArray) . ')';
64 $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params},\$_smarty_tpl)";
66 $_params = implode(",", $_attr);
67 $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params})";
71 $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}";
74 if (empty($_assign)) {
75 // This tag does create output
76 $compiler->has_output = true;
77 $output = "<?php echo {$return};?>\n";
79 $output = "<?php \$_smarty_tpl->assign({$_assign},{$return});?>\n";