fusionpbx/resources/templates/engine/smarty/sysplugins/smarty_internal_compile_ass...

97 lines
3.3 KiB
PHP
Raw Normal View History

2013-11-09 21:02:56 +01:00
<?php
/**
* Smarty Internal Plugin Compile Assign
* Compiles the {assign} tag
*
2018-11-07 08:18:14 +01:00
* @package Smarty
2013-11-09 21:02:56 +01:00
* @subpackage Compiler
2018-11-07 08:18:14 +01:00
* @author Uwe Tews
2013-11-09 21:02:56 +01:00
*/
/**
* Smarty Internal Plugin Compile Assign Class
*
2018-11-07 08:18:14 +01:00
* @package Smarty
2013-11-09 21:02:56 +01:00
* @subpackage Compiler
*/
class Smarty_Internal_Compile_Assign extends Smarty_Internal_CompileBase
{
2018-11-07 08:18:14 +01:00
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see Smarty_Internal_CompileBase
*/
public $option_flags = array('nocache', 'noscope');
/**
* Valid scope names
*
* @var array
*/
public $valid_scopes = array(
'local' => Smarty::SCOPE_LOCAL, 'parent' => Smarty::SCOPE_PARENT,
'root' => Smarty::SCOPE_ROOT, 'global' => Smarty::SCOPE_GLOBAL,
'tpl_root' => Smarty::SCOPE_TPL_ROOT, 'smarty' => Smarty::SCOPE_SMARTY
);
2013-11-09 21:02:56 +01:00
/**
* Compiles code for the {assign} tag
*
2018-11-07 08:18:14 +01:00
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
2013-11-09 21:02:56 +01:00
* @return string compiled code
2018-11-07 08:18:14 +01:00
* @throws \SmartyCompilerException
2013-11-09 21:02:56 +01:00
*/
2018-11-07 08:18:14 +01:00
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
2013-11-09 21:02:56 +01:00
{
// the following must be assigned at runtime because it will be overwritten in Smarty_Internal_Compile_Append
$this->required_attributes = array('var', 'value');
$this->shorttag_order = array('var', 'value');
$this->optional_attributes = array('scope');
2018-11-07 08:18:14 +01:00
$this->mapCache = array();
$_nocache = false;
2013-11-09 21:02:56 +01:00
// check and get attributes
$_attr = $this->getAttributes($compiler, $args);
// nocache ?
2018-11-07 08:18:14 +01:00
if ($_var = $compiler->getId($_attr[ 'var' ])) {
$_var = "'{$_var}'";
} else {
$_var = $_attr[ 'var' ];
}
2013-11-09 21:02:56 +01:00
if ($compiler->tag_nocache || $compiler->nocache) {
2018-11-07 08:18:14 +01:00
$_nocache = true;
2013-11-09 21:02:56 +01:00
// create nocache var to make it know for further compiling
2018-11-07 08:18:14 +01:00
$compiler->setNocacheInVariable($_attr[ 'var' ]);
2013-11-09 21:02:56 +01:00
}
// scope setup
2018-11-07 08:18:14 +01:00
if ($_attr[ 'noscope' ]) {
$_scope = -1;
2013-11-09 21:02:56 +01:00
} else {
2018-11-07 08:18:14 +01:00
$_scope = $compiler->convertScope($_attr, $this->valid_scopes);
2013-11-09 21:02:56 +01:00
}
2018-11-07 08:18:14 +01:00
// optional parameter
$_params = '';
if ($_nocache || $_scope) {
$_params .= ' ,' . var_export($_nocache, true);
2013-11-09 21:02:56 +01:00
}
2018-11-07 08:18:14 +01:00
if ($_scope) {
$_params .= ' ,' . $_scope;
}
if (isset($parameter[ 'smarty_internal_index' ])) {
$output =
"<?php \$_tmp_array = isset(\$_smarty_tpl->tpl_vars[{$_var}]) ? \$_smarty_tpl->tpl_vars[{$_var}]->value : array();\n";
$output .= "if (!is_array(\$_tmp_array) || \$_tmp_array instanceof ArrayAccess) {\n";
$output .= "settype(\$_tmp_array, 'array');\n";
$output .= "}\n";
$output .= "\$_tmp_array{$parameter['smarty_internal_index']} = {$_attr['value']};\n";
$output .= "\$_smarty_tpl->_assignInScope({$_var}, \$_tmp_array{$_params});?>";
} else {
$output = "<?php \$_smarty_tpl->_assignInScope({$_var}, {$_attr['value']}{$_params});?>";
2013-11-09 21:02:56 +01:00
}
return $output;
}
}