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.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. * @throws \SmartyCompilerException
  36. * @throws \SmartyException
  37. */
  38. public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method)
  39. {
  40. // check and get attributes
  41. $_attr = $this->getAttributes($compiler, $args);
  42. unset($_attr[ 'nocache' ]);
  43. $_assign = null;
  44. if (isset($_attr[ 'assign' ])) {
  45. $_assign = $_attr[ 'assign' ];
  46. unset($_attr[ 'assign' ]);
  47. }
  48. // method or property ?
  49. if (is_callable(array($compiler->smarty->registered_objects[ $tag ][ 0 ], $method))) {
  50. // convert attributes into parameter array string
  51. if ($compiler->smarty->registered_objects[ $tag ][ 2 ]) {
  52. $_paramsArray = array();
  53. foreach ($_attr as $_key => $_value) {
  54. if (is_int($_key)) {
  55. $_paramsArray[] = "$_key=>$_value";
  56. } else {
  57. $_paramsArray[] = "'$_key'=>$_value";
  58. }
  59. }
  60. $_params = 'array(' . implode(',', $_paramsArray) . ')';
  61. $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params},\$_smarty_tpl)";
  62. } else {
  63. $_params = implode(',', $_attr);
  64. $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params})";
  65. }
  66. } else {
  67. // object property
  68. $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}";
  69. }
  70. if (!empty($parameter[ 'modifierlist' ])) {
  71. $output = $compiler->compileTag('private_modifier', array(),
  72. array('modifierlist' => $parameter[ 'modifierlist' ], 'value' => $output));
  73. }
  74. if (empty($_assign)) {
  75. return "<?php echo {$output};?>\n";
  76. } else {
  77. return "<?php \$_smarty_tpl->assign({$_assign},{$output});?>\n";
  78. }
  79. }
  80. }