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_appendbyref.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Smarty Method AppendByRef
  4. *
  5. * Smarty::appendByRef() method
  6. *
  7. * @package Smarty
  8. * @subpackage PluginsInternal
  9. * @author Uwe Tews
  10. */
  11. class Smarty_Internal_Method_AppendByRef
  12. {
  13. /**
  14. * appends values to template variables by reference
  15. *
  16. * @api Smarty::appendByRef()
  17. * @link http://www.smarty.net/docs/en/api.append.by.ref.tpl
  18. *
  19. * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
  20. * @param string $tpl_var the template variable name
  21. * @param mixed &$value the referenced value to append
  22. * @param bool $merge flag if array elements shall be merged
  23. *
  24. * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
  25. */
  26. public static function appendByRef(Smarty_Internal_Data $data, $tpl_var, &$value, $merge = false)
  27. {
  28. if ($tpl_var != '' && isset($value)) {
  29. if (!isset($data->tpl_vars[$tpl_var])) {
  30. $data->tpl_vars[$tpl_var] = new Smarty_Variable();
  31. }
  32. if (!is_array($data->tpl_vars[$tpl_var]->value)) {
  33. settype($data->tpl_vars[$tpl_var]->value, 'array');
  34. }
  35. if ($merge && is_array($value)) {
  36. foreach ($value as $_key => $_val) {
  37. $data->tpl_vars[$tpl_var]->value[$_key] = &$value[$_key];
  38. }
  39. } else {
  40. $data->tpl_vars[$tpl_var]->value[] = &$value;
  41. }
  42. if ($data->_objType == 2 && $data->scope) {
  43. $data->ext->_updateScope->updateScope($data, $tpl_var);
  44. }
  45. }
  46. return $data;
  47. }
  48. }