]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_runtime_make_nocache.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_runtime_make_nocache.php
1 <?php
2
3 /**
4  * {make_nocache} Runtime Methods save(), store()
5  *
6  * @package    Smarty
7  * @subpackage PluginsInternal
8  * @author     Uwe Tews
9  *
10  */
11 class Smarty_Internal_Runtime_Make_Nocache
12 {
13
14     /**
15      * Save current variable value while rendering compiled template and inject nocache code to
16      * assign variable value in cahed template
17      *
18      * @param \Smarty_Internal_Template $tpl
19      * @param string                    $var variable name
20      *
21      * @throws \SmartyException
22      */
23     public function save(Smarty_Internal_Template $tpl, $var)
24     {
25         if (isset($tpl->tpl_vars[ $var ])) {
26             $export =
27                 preg_replace('/^Smarty_Variable::__set_state[(]|[)]$/', '', var_export($tpl->tpl_vars[ $var ], true));
28             if (preg_match('/(\w+)::__set_state/', $export, $match)) {
29                 throw new SmartyException("{make_nocache \${$var}} in template '{$tpl->source->name}': variable does contain object '{$match[1]}' not implementing method '__set_state'");
30             }
31             echo "/*%%SmartyNocache:{$tpl->compiled->nocache_hash}%%*/<?php " .
32                  addcslashes("\$_smarty_tpl->smarty->ext->_make_nocache->store(\$_smarty_tpl, '{$var}', ", '\\') .
33                  $export . ");?>\n/*/%%SmartyNocache:{$tpl->compiled->nocache_hash}%%*/";
34         }
35     }
36
37     /**
38      * Store variable value saved while rendering compiled template in cached template context
39      *
40      * @param \Smarty_Internal_Template $tpl
41      * @param  string                   $var variable name
42      * @param  array                    $properties
43      */
44     public function store(Smarty_Internal_Template $tpl, $var, $properties)
45     {
46         // do not overwrite existing nocache variables
47         if (!isset($tpl->tpl_vars[ $var ]) || !$tpl->tpl_vars[ $var ]->nocache) {
48             $newVar = new Smarty_Variable();
49             unset($properties[ 'nocache' ]);
50             foreach ($properties as $k => $v) {
51                 $newVar->$k = $v;
52             }
53             $tpl->tpl_vars[ $var ] = $newVar;
54         }
55     }
56 }