- move template function code into runtime extension

This commit is contained in:
uwetews
2015-09-01 02:30:56 +02:00
parent 2ba7109043
commit d2fa4083f7
3 changed files with 52 additions and 2 deletions

View File

@@ -2,6 +2,8 @@
01.09.2015 01.09.2015
- improvement convert template inheritance into runtime processing - improvement convert template inheritance into runtime processing
- bugfix {$smarty.block.parent} did always reference the root parent block https://github.com/smarty-php/smarty/issues/68 - bugfix {$smarty.block.parent} did always reference the root parent block https://github.com/smarty-php/smarty/issues/68
- move subtemplate code into runtime extension and optimize for size and speed
- move template function code into runtime extension
23.08.2015 23.08.2015
- introduce Smarty::$resource_cache_mode and cache template object of {include} inside loop - introduce Smarty::$resource_cache_mode and cache template object of {include} inside loop

View File

@@ -76,9 +76,9 @@ class Smarty_Internal_Compile_Call extends Smarty_Internal_CompileBase
//$compiler->suppressNocacheProcessing = true; //$compiler->suppressNocacheProcessing = true;
// was there an assign attribute // was there an assign attribute
if (isset($_assign)) { if (isset($_assign)) {
$_output = "<?php ob_start();\$_smarty_tpl->callTemplateFunction ({$_name}, \$_smarty_tpl, {$_params}, {$_nocache}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n"; $_output = "<?php ob_start();\n\$_smarty_tpl->_Function->callTemplateFunction({$_name}, \$_smarty_tpl, {$_params}, {$_nocache});\n\$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
} else { } else {
$_output = "<?php \$_smarty_tpl->callTemplateFunction ({$_name}, \$_smarty_tpl, {$_params}, {$_nocache});?>\n"; $_output = "<?php \$_smarty_tpl->_Function->callTemplateFunction({$_name}, \$_smarty_tpl, {$_params}, {$_nocache});?>\n";
} }
return $_output; return $_output;
} }

View File

@@ -0,0 +1,48 @@
<?php
/**
* Runtime Method _callTemplateFunction
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*
**/
class Smarty_Internal_Runtime_Function
{
/**
* Call template function
*
* @param string $name template function name
* @param object|\Smarty_Internal_Template $_smarty_tpl template object
* @param array $params parameter array
* @param bool $nocache true if called nocache
*
* @throws \SmartyException
*/
public function callTemplateFunction($name, Smarty_Internal_Template $_smarty_tpl, $params, $nocache)
{
if (isset($_smarty_tpl->tpl_function[$name])) {
if (!$_smarty_tpl->caching || ($_smarty_tpl->caching && $nocache)) {
$function = $_smarty_tpl->tpl_function[$name]['call_name'];
} else {
if (isset($_smarty_tpl->tpl_function[$name]['call_name_caching'])) {
$function = $_smarty_tpl->tpl_function[$name]['call_name_caching'];
} else {
$function = $_smarty_tpl->tpl_function[$name]['call_name'];
}
}
if (function_exists($function)) {
$function ($_smarty_tpl, $params);
return;
}
// try to load template function dynamically
if (Smarty_Internal_Function_Call_Handler::call($name, $_smarty_tpl, $function)) {
$function ($_smarty_tpl, $params);
return;
}
}
throw new SmartyException("Unable to find template function '{$name}'");
}
}