[gosa.git] / gosa-core / include / smarty / sysplugins / smarty_internal_compile_private_object_function.php
1 <?php
2 /**
3 * Smarty Internal Plugin Compile Object Funtion
4 *
5 * Compiles code for registered objects as function
6 *
7 * @package Smarty
8 * @subpackage Compiler
9 * @author Uwe Tews
10 */
11 /**
12 * Smarty Internal Plugin Compile Object Function Class
13 */
14 class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_CompileBase {
15 /**
16 * Compiles code for the execution of function plugin
17 *
18 * @param array $args array with attributes from parser
19 * @param string $tag name of function
20 * @param string $methode name of methode to call
21 * @param object $compiler compiler object
22 * @return string compiled code
23 */
24 public function compile($args, $compiler, $tag, $methode)
25 {
26 $this->compiler = $compiler;
27 $this->required_attributes = array();
28 $this->optional_attributes = array('_any');
29 // check and get attributes
30 $_attr = $this->_get_attributes($args);
31 $_assign = null;
32 if (isset($_attr['assign'])) {
33 $_assign = $_attr['assign'];
34 unset($_attr['assign']);
35 }
36 // convert attributes into parameter array string
37 if ($this->compiler->smarty->registered_objects[$tag][2]) {
38 $_paramsArray = array();
39 foreach ($_attr as $_key => $_value) {
40 if (is_int($_key)) {
41 $_paramsArray[] = "$_key=>$_value";
42 } else {
43 $_paramsArray[] = "'$_key'=>$_value";
44 }
45 }
46 $_params = 'array(' . implode(",", $_paramsArray) . ')';
47 $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$methode}({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl)";
48 } else {
49 $_params = implode(",", $_attr);
50 $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$methode}({$_params})";
51 }
52 if (empty($_assign)) {
53 // This tag does create output
54 $this->compiler->has_output = true;
55 $output = "<?php echo {$return};?>\n";
56 } else {
57 $output = "<?php \$_smarty_tpl->assign({$_assign},{$return});?>\n";
58 }
59 return $output;
60 }
61 }
62 ?>