smarty_internal_compile_assign.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Smarty Internal Plugin Compile Assign
  4. *
  5. * Compiles the {assign} tag
  6. *
  7. * @package Smarty
  8. * @subpackage Compiler
  9. * @author Uwe Tews
  10. */
  11. /**
  12. * Smarty Internal Plugin Compile Assign Class
  13. */
  14. class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase {
  15. /**
  16. * Compiles code for the {assign} tag
  17. *
  18. * @param array $args array with attributes from parser
  19. * @param object $compiler compiler object
  20. * @return string compiled code
  21. */
  22. public function compile($args, $compiler)
  23. {
  24. $this->compiler = $compiler;
  25. $this->required_attributes = array('var', 'value');
  26. $this->optional_attributes = array('scope', 'nocache', 'smarty_internal_index');
  27. $_nocache = 'null';
  28. $_scope = 'null';
  29. // check for nocache attribute before _get_attributes because
  30. // it shall not controll caching of the compiled code, but is a parameter
  31. if (isset($args['nocache'])) {
  32. if ($args['nocache'] == 'true') {
  33. $_nocache = 'true';
  34. $_nocache_boolean = true;
  35. }
  36. unset($args['nocache']);
  37. }
  38. // check and get attributes
  39. $_attr = $this->_get_attributes($args);
  40. if (isset($_attr['scope'])) {
  41. if ($_attr['scope'] == '\'parent\'') {
  42. $_scope = SMARTY_PARENT_SCOPE;
  43. } elseif ($_attr['scope'] == '\'root\'') {
  44. $_scope = SMARTY_ROOT_SCOPE;
  45. } elseif ($_attr['scope'] == '\'global\'') {
  46. $_scope = SMARTY_GLOBAL_SCOPE;
  47. }
  48. }
  49. // compiled output
  50. if (isset($_attr['smarty_internal_index'])) {
  51. return "<?php if (!isset(\$_smarty_tpl->tpl_vars[$_attr[var]]) || !is_array(\$_smarty_tpl->tpl_vars[$_attr[var]]->value)) \$_smarty_tpl->createLocalArrayVariable($_attr[var], $_nocache, $_scope);\n\$_smarty_tpl->tpl_vars[$_attr[var]]->value$_attr[smarty_internal_index] = $_attr[value];?>";
  52. } else {
  53. return "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);?>";
  54. }
  55. }
  56. }
  57. ?>