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_runtime_updatescope.php 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Runtime Methods updateScope
  4. *
  5. * @package Smarty
  6. * @subpackage PluginsInternal
  7. * @author Uwe Tews
  8. *
  9. **/
  10. class Smarty_Internal_Runtime_UpdateScope
  11. {
  12. /**
  13. * Update new assigned template variable in other effected scopes
  14. *
  15. * @param \Smarty_Internal_Template $tpl template object
  16. * @param string $varName variable name
  17. * @param int $scope scope to which bubble up variable value
  18. */
  19. public function updateScope(Smarty_Internal_Template $tpl, $varName, $scope = Smarty::SCOPE_LOCAL)
  20. {
  21. if (!$scope && !$tpl->scope) {
  22. return;
  23. }
  24. foreach (array($scope, $tpl->scope) as $s) {
  25. $s = ($bubble_up = $s >= Smarty::SCOPE_BUBBLE_UP) ? $s - Smarty::SCOPE_BUBBLE_UP : $s;
  26. if ($bubble_up && $s) {
  27. $ptr = $tpl->parent;
  28. if (isset($ptr)) {
  29. $ptr->tpl_vars[$varName] = $tpl->tpl_vars[$varName];
  30. $ptr = $ptr->parent;
  31. }
  32. if ($s == Smarty::SCOPE_PARENT) {
  33. continue;
  34. }
  35. while (isset($ptr) && $ptr->_objType == 2) {
  36. $ptr->tpl_vars[$varName] = $tpl->tpl_vars[$varName];
  37. $ptr = $ptr->parent;
  38. }
  39. if ($s == Smarty::SCOPE_TPL_ROOT) {
  40. continue;
  41. } elseif ($s == Smarty::SCOPE_SMARTY) {
  42. $tpl->smarty->tpl_vars[$varName] = $tpl->tpl_vars[$varName];
  43. } elseif ($s == Smarty::SCOPE_GLOBAL) {
  44. Smarty::$global_tpl_vars[$varName] = $tpl->tpl_vars[$varName];
  45. } elseif ($s == Smarty::SCOPE_ROOT) {
  46. while (isset($ptr->parent)) {
  47. $ptr = $ptr->parent;
  48. }
  49. $ptr->tpl_vars[$varName] = $tpl->tpl_vars[$varName];
  50. }
  51. }
  52. }
  53. }
  54. }