You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smarty_internal_compile_private_object_function.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. * Smarty Internal Plugin Compile Object Function Class
  12. *
  13. * @package Smarty
  14. * @subpackage Compiler
  15. */
  16. class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_CompileBase
  17. {
  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 \Smarty_Internal_TemplateCompilerBase $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. *
  34. * @return string compiled code
  35. */
  36. public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method)
  37. {
  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. if (empty($_assign)) {
  72. // This tag does create output
  73. $compiler->has_output = true;
  74. $output = "<?php echo {$return};?>\n";
  75. } else {
  76. $output = "<?php \$_smarty_tpl->assign({$_assign},{$return});?>\n";
  77. }
  78. return $output;
  79. }
  80. }