]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_method_appendbyref.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_method_appendbyref.php
1 <?php
2
3 /**
4  * Smarty Method AppendByRef
5  *
6  * Smarty::appendByRef() method
7  *
8  * @package    Smarty
9  * @subpackage PluginsInternal
10  * @author     Uwe Tews
11  */
12 class Smarty_Internal_Method_AppendByRef
13 {
14
15     /**
16      * appends values to template variables by reference
17      *
18      * @api  Smarty::appendByRef()
19      * @link http://www.smarty.net/docs/en/api.append.by.ref.tpl
20      *
21      * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
22      * @param  string                                                 $tpl_var the template variable name
23      * @param  mixed                                                  &$value  the referenced value to append
24      * @param  bool                                                   $merge   flag if array elements shall be merged
25      *
26      * @return \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty
27      */
28     public static function appendByRef(Smarty_Internal_Data $data, $tpl_var, &$value, $merge = false)
29     {
30         if ($tpl_var != '' && isset($value)) {
31             if (!isset($data->tpl_vars[ $tpl_var ])) {
32                 $data->tpl_vars[ $tpl_var ] = new Smarty_Variable();
33             }
34             if (!is_array($data->tpl_vars[ $tpl_var ]->value)) {
35                 settype($data->tpl_vars[ $tpl_var ]->value, 'array');
36             }
37             if ($merge && is_array($value)) {
38                 foreach ($value as $_key => $_val) {
39                     $data->tpl_vars[ $tpl_var ]->value[ $_key ] = &$value[ $_key ];
40                 }
41             } else {
42                 $data->tpl_vars[ $tpl_var ]->value[] = &$value;
43             }
44             if ($data->_isTplObj() && $data->scope) {
45                 $data->ext->_updateScope->_updateScope($data, $tpl_var);
46             }
47         }
48         return $data;
49     }
50 }