3 * Smarty Internal Plugin Compile Object Funtion
5 * Compiles code for registered objects as function
13 * Smarty Internal Plugin Compile Object Function Class
15 class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_CompileBase {
16 // attribute definitions
17 public $required_attributes = array();
18 public $optional_attributes = array('_any');
21 * Compiles code for the execution of function plugin
23 * @param array $args array with attributes from parser
24 * @param object $compiler compiler object
25 * @param array $parameter array with compilation parameter
26 * @param string $tag name of function
27 * @param string $methode name of methode to call
28 * @return string compiled code
30 public function compile($args, $compiler, $parameter, $tag, $methode)
32 $this->compiler = $compiler;
33 // check and get attributes
34 $_attr = $this->_get_attributes($args);
35 if ($_attr['nocache'] === true) {
36 $this->compiler->tag_nocache = true;
38 unset($_attr['nocache']);
40 if (isset($_attr['assign'])) {
41 $_assign = $_attr['assign'];
42 unset($_attr['assign']);
44 // convert attributes into parameter array string
45 if ($this->compiler->smarty->registered_objects[$tag][2]) {
46 $_paramsArray = array();
47 foreach ($_attr as $_key => $_value) {
49 $_paramsArray[] = "$_key=>$_value";
51 $_paramsArray[] = "'$_key'=>$_value";
54 $_params = 'array(' . implode(",", $_paramsArray) . ')';
55 $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$methode}({$_params},\$_smarty_tpl)";
57 $_params = implode(",", $_attr);
58 $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$methode}({$_params})";
60 if (empty($_assign)) {
61 // This tag does create output
62 $this->compiler->has_output = true;
63 $output = "<?php echo {$return};?>\n";
65 $output = "<?php \$_smarty_tpl->assign({$_assign},{$return});?>\n";