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_method_append.php 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Smarty Method Append
  4. *
  5. * Smarty::append() method
  6. *
  7. * @package Smarty
  8. * @subpackage PluginsInternal
  9. * @author Uwe Tews
  10. */
  11. class Smarty_Internal_Method_Append
  12. {
  13. /**
  14. * Valid for all objects
  15. *
  16. * @var int
  17. */
  18. public $objMap = 7;
  19. /**
  20. * appends values to template variables
  21. *
  22. * @api Smarty::append()
  23. * @link http://www.smarty.net/docs/en/api.append.tpl
  24. *
  25. * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
  26. * @param array|string $tpl_var the template variable name(s)
  27. * @param mixed $value the value to append
  28. * @param bool $merge flag if array elements shall be merged
  29. * @param bool $nocache if true any output of this variable will
  30. * be not cached
  31. *
  32. * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
  33. */
  34. public function append(Smarty_Internal_Data $data, $tpl_var, $value = null, $merge = false, $nocache = false)
  35. {
  36. if (is_array($tpl_var)) {
  37. // $tpl_var is an array, ignore $value
  38. foreach ($tpl_var as $_key => $_val) {
  39. if ($_key !== '') {
  40. $this->append($data, $_key, $_val, $merge, $nocache);
  41. }
  42. }
  43. } else {
  44. if ($tpl_var !== '' && isset($value)) {
  45. if (!isset($data->tpl_vars[ $tpl_var ])) {
  46. $tpl_var_inst = $data->ext->getTemplateVars->_getVariable($data, $tpl_var, null, true, false);
  47. if ($tpl_var_inst instanceof Smarty_Undefined_Variable) {
  48. $data->tpl_vars[ $tpl_var ] = new Smarty_Variable(null, $nocache);
  49. } else {
  50. $data->tpl_vars[ $tpl_var ] = clone $tpl_var_inst;
  51. }
  52. }
  53. if (!(is_array($data->tpl_vars[ $tpl_var ]->value) ||
  54. $data->tpl_vars[ $tpl_var ]->value instanceof ArrayAccess)
  55. ) {
  56. settype($data->tpl_vars[ $tpl_var ]->value, 'array');
  57. }
  58. if ($merge && is_array($value)) {
  59. foreach ($value as $_mkey => $_mval) {
  60. $data->tpl_vars[ $tpl_var ]->value[ $_mkey ] = $_mval;
  61. }
  62. } else {
  63. $data->tpl_vars[ $tpl_var ]->value[] = $value;
  64. }
  65. }
  66. if ($data->_isTplObj() && $data->scope) {
  67. $data->ext->_updateScope->_updateScope($data, $tpl_var);
  68. }
  69. }
  70. return $data;
  71. }
  72. }