4 * {make_nocache} Runtime Methods save(), store()
7 * @subpackage PluginsInternal
11 class Smarty_Internal_Runtime_Make_Nocache
15 * Save current variable value while rendering compiled template and inject nocache code to
16 * assign variable value in cahed template
18 * @param \Smarty_Internal_Template $tpl
19 * @param string $var variable name
21 * @throws \SmartyException
23 public function save(Smarty_Internal_Template $tpl, $var)
25 if (isset($tpl->tpl_vars[ $var ])) {
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'");
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}%%*/";
38 * Store variable value saved while rendering compiled template in cached template context
40 * @param \Smarty_Internal_Template $tpl
41 * @param string $var variable name
42 * @param array $properties
44 public function store(Smarty_Internal_Template $tpl, $var, $properties)
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) {
53 $tpl->tpl_vars[ $var ] = $newVar;