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