Initial repo created
[timetracker.git] / WEB-INF / lib / smarty / sysplugins / smarty_internal_compile_assign.php
1 <?php
2
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 /**
14  * Smarty Internal Plugin Compile Assign Class
15  */
16 class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase {
17     /**
18      * Compiles code for the {assign} tag
19      * 
20      * @param array $args array with attributes from parser
21      * @param object $compiler compiler object
22      * @param array $parameter array with compilation parameter
23      * @return string compiled code
24      */
25     public function compile($args, $compiler, $parameter)
26     {
27         $this->compiler = $compiler;
28         // the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append
29         $this->required_attributes = array('var', 'value');
30         $this->shorttag_order = array('var', 'value');
31         $this->optional_attributes = array('scope');
32         $_nocache = 'null';
33         $_scope = 'null'; 
34         // check and get attributes
35         $_attr = $this->_get_attributes($args); 
36                 // nocache ?
37         if ($this->compiler->tag_nocache || $this->compiler->nocache) {
38             $_nocache = 'true'; 
39             // create nocache var to make it know for further compiling
40             $compiler->template->tpl_vars[trim($_attr['var'], "'")] = new Smarty_variable(null, true);
41         } 
42         // scope setup
43         if (isset($_attr['scope'])) {
44             $_attr['scope'] = trim($_attr['scope'], "'\"");
45             if ($_attr['scope'] == 'parent') {
46                 $_scope = Smarty::SCOPE_PARENT;
47             } elseif ($_attr['scope'] == 'root') {
48                 $_scope = Smarty::SCOPE_ROOT;
49             } elseif ($_attr['scope'] == 'global') {
50                 $_scope = Smarty::SCOPE_GLOBAL;
51             } else {
52                 $this->compiler->trigger_template_error('illegal value for "scope" attribute', $this->compiler->lex->taglineno);
53             } 
54         } 
55         // compiled output
56         if (isset($parameter['smarty_internal_index'])) {
57             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$parameter[smarty_internal_index] = $_attr[value];?>";
58         } else {
59             return "<?php \$_smarty_tpl->tpl_vars[$_attr[var]] = new Smarty_variable($_attr[value], $_nocache, $_scope);?>";
60         } 
61     } 
62
63
64 ?>