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_function_plugin.php 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Function Plugin
  4. * Compiles code for the execution of function plugin
  5. *
  6. * @package Smarty
  7. * @subpackage Compiler
  8. * @author Uwe Tews
  9. */
  10. /**
  11. * Smarty Internal Plugin Compile Function Plugin Class
  12. *
  13. * @package Smarty
  14. * @subpackage Compiler
  15. */
  16. class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_CompileBase
  17. {
  18. /**
  19. * Attribute definition: Overwrites base class.
  20. *
  21. * @var array
  22. * @see Smarty_Internal_CompileBase
  23. */
  24. public $required_attributes = array();
  25. /**
  26. * Attribute definition: Overwrites base class.
  27. *
  28. * @var array
  29. * @see Smarty_Internal_CompileBase
  30. */
  31. public $optional_attributes = array('_any');
  32. /**
  33. * Compiles code for the execution of function plugin
  34. *
  35. * @param array $args array with attributes from parser
  36. * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
  37. * @param array $parameter array with compilation parameter
  38. * @param string $tag name of function plugin
  39. * @param string $function PHP function name
  40. *
  41. * @return string compiled code
  42. * @throws \SmartyCompilerException
  43. * @throws \SmartyException
  44. */
  45. public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $function)
  46. {
  47. // check and get attributes
  48. $_attr = $this->getAttributes($compiler, $args);
  49. unset($_attr[ 'nocache' ]);
  50. // convert attributes into parameter array string
  51. $_paramsArray = array();
  52. foreach ($_attr as $_key => $_value) {
  53. if (is_int($_key)) {
  54. $_paramsArray[] = "$_key=>$_value";
  55. } else {
  56. $_paramsArray[] = "'$_key'=>$_value";
  57. }
  58. }
  59. $_params = 'array(' . implode(',', $_paramsArray) . ')';
  60. // compile code
  61. $output = "{$function}({$_params},\$_smarty_tpl)";
  62. if (!empty($parameter[ 'modifierlist' ])) {
  63. $output = $compiler->compileTag('private_modifier', array(),
  64. array('modifierlist' => $parameter[ 'modifierlist' ],
  65. 'value' => $output));
  66. }
  67. $output = "<?php echo {$output};?>\n";
  68. return $output;
  69. }
  70. }