From 49d54c0c3199fb8e380ce68f8fb08a308ddf56a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Eduardo?= Date: Mon, 25 Dec 2017 16:58:41 -0500 Subject: =?UTF-8?q?migraci=C3=B3n=20mayor=20a=20smarty=20PHP?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../smarty_internal_runtime_make_nocache.php | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 smarty/sysplugins/smarty_internal_runtime_make_nocache.php (limited to 'smarty/sysplugins/smarty_internal_runtime_make_nocache.php') diff --git a/smarty/sysplugins/smarty_internal_runtime_make_nocache.php b/smarty/sysplugins/smarty_internal_runtime_make_nocache.php new file mode 100644 index 0000000..dd9e15f --- /dev/null +++ b/smarty/sysplugins/smarty_internal_runtime_make_nocache.php @@ -0,0 +1,56 @@ +tpl_vars[ $var ])) { + $export = preg_replace('/^Smarty_Variable::__set_state[(]|\s|[)]$/', '', + var_export($tpl->tpl_vars[ $var ], true)); + if (preg_match('/(\w+)::__set_state/', $export, $match)) { + throw new SmartyException("{make_nocache \${$var}} in template '{$tpl->source->name}': variable does contain object '{$match[1]}' not implementing method '__set_state'"); + } + echo "/*%%SmartyNocache:{$tpl->compiled->nocache_hash}%%*/smarty->ext->_make_nocache->store(\$_smarty_tpl, '{$var}', " . $export, + '\\') . ");?>\n/*/%%SmartyNocache:{$tpl->compiled->nocache_hash}%%*/"; + } + } + + /** + * Store variable value saved while rendering compiled template in cached template context + * + * @param \Smarty_Internal_Template $tpl + * @param string $var variable name + * @param array $properties + */ + public function store(Smarty_Internal_Template $tpl, $var, $properties) + { + // do not overwrite existing nocache variables + if (!isset($tpl->tpl_vars[ $var ]) || !$tpl->tpl_vars[ $var ]->nocache) { + $newVar = new Smarty_Variable(); + unset($properties[ 'nocache' ]); + foreach ($properties as $k => $v) { + $newVar->$k = $v; + } + $tpl->tpl_vars[ $var ] = $newVar; + } + } +} -- cgit v1.2.3