smarty_internal_compile_private_object_function.php 2.5 KB

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