- bugfix change compiled code for registered function and modifiers to called as callable to allow closures

https://github.com/smarty-php/smarty/pull/368
This commit is contained in:
uwetews
2017-05-27 11:30:21 +02:00
parent e51b0ac4af
commit ef889c79e0
4 changed files with 14 additions and 24 deletions

View File

@@ -1,4 +1,8 @@
===== 3.1.32 - dev === ===== 3.1.32 - dev ===
27.5.2017
- bugfix change compiled code for registered function and modifiers to called as callable to allow closures
https://github.com/smarty-php/smarty/pull/368
21.5.2017 21.5.2017
- performance store flag for already required shared plugin functions in static variable or - performance store flag for already required shared plugin functions in static variable or
Smarty's $_cache to improve performance when plugins are often called Smarty's $_cache to improve performance when plugins are often called

View File

@@ -108,7 +108,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/** /**
* smarty version * smarty version
*/ */
const SMARTY_VERSION = '3.1.32-dev-8'; const SMARTY_VERSION = '3.1.32-dev-9';
/** /**
* define variable scopes * define variable scopes

View File

@@ -48,20 +48,13 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
case 1: case 1:
// registered modifier // registered modifier
if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])) { if (isset($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ])) {
$function = if (is_callable($compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ])) {
$compiler->smarty->registered_plugins[ Smarty::PLUGIN_MODIFIER ][ $modifier ][ 0 ]; $output =
if (!is_array($function)) { sprintf('call_user_func_array($_smarty_tpl->registered_plugins[ \'%s\' ][ %s ][ 0 ], array( %s ))',
$output = "{$function}({$params})"; Smarty::PLUGIN_MODIFIER, var_export($modifier, true), $params);
} else { $compiler->known_modifier_type[ $modifier ] = $type;
if (is_object($function[ 0 ])) { break 2;
$output = '$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_MODIFIER][\'' .
$modifier . '\'][0][0]->' . $function[ 1 ] . '(' . $params . ')';
} else {
$output = $function[ 0 ] . '::' . $function[ 1 ] . '(' . $params . ')';
}
} }
$compiler->known_modifier_type[ $modifier ] = $type;
break 2;
} }
break; break;
case 2: case 2:
@@ -154,4 +147,4 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
return $output; return $output;
} }
} }

View File

@@ -61,14 +61,7 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
$_params = 'array(' . implode(",", $_paramsArray) . ')'; $_params = 'array(' . implode(",", $_paramsArray) . ')';
$function = $tag_info[ 0 ]; $function = $tag_info[ 0 ];
// compile code // compile code
if (!is_array($function)) { $output = "call_user_func_array( \$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0], array( {$_params},\$_smarty_tpl ) )";
$output = "{$function}({$_params},\$_smarty_tpl)";
} elseif (is_object($function[ 0 ])) {
$output =
"\$_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl)";
} else {
$output = "{$function[0]}::{$function[1]}({$_params},\$_smarty_tpl)";
}
if (!empty($parameter[ 'modifierlist' ])) { if (!empty($parameter[ 'modifierlist' ])) {
$output = $compiler->compileTag('private_modifier', array(), $output = $compiler->compileTag('private_modifier', array(),
array('modifierlist' => $parameter[ 'modifierlist' ], array('modifierlist' => $parameter[ 'modifierlist' ],
@@ -79,4 +72,4 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
$output = "<?php echo {$output};?>\n"; $output = "<?php echo {$output};?>\n";
return $output; return $output;
} }
} }