From e62dcaa6a9abd085c27c37d44dc5361497b2c80f Mon Sep 17 00:00:00 2001 From: "Uwe.Tews@googlemail.com" Date: Sat, 27 Jul 2013 09:48:42 +0000 Subject: [PATCH] - enhancement allow access to properties of registered opjects for Smarty2 BC (forum topic 24344) --- change_log.txt | 3 ++ ...ternal_compile_private_object_function.php | 35 +++++++++++-------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/change_log.txt b/change_log.txt index 2e862603..80992bce 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== +27.07.2013 +- enhancement allow access to properties of registered opjects for Smarty2 BC (forum topic 24344) + 26.07.2013 - bugfix template inheritance nesting problem (forum topic 24387) diff --git a/libs/sysplugins/smarty_internal_compile_private_object_function.php b/libs/sysplugins/smarty_internal_compile_private_object_function.php index c5a56809..d260eb57 100644 --- a/libs/sysplugins/smarty_internal_compile_private_object_function.php +++ b/libs/sysplugins/smarty_internal_compile_private_object_function.php @@ -28,9 +28,9 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co /** * Compiles code for the execution of function plugin * - * @param array $args array with attributes from parser + * @param array $args array with attributes from parser * @param object $compiler compiler object - * @param array $parameter array with compilation parameter + * @param array $parameter array with compilation parameter * @param string $tag name of function * @param string $method name of method to call * @return string compiled code @@ -48,22 +48,29 @@ class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_Co $_assign = $_attr['assign']; unset($_attr['assign']); } - // convert attributes into parameter array string - if ($compiler->smarty->registered_objects[$tag][2]) { - $_paramsArray = array(); - foreach ($_attr as $_key => $_value) { - if (is_int($_key)) { - $_paramsArray[] = "$_key=>$_value"; - } else { - $_paramsArray[] = "'$_key'=>$_value"; + // method or property ? + if (method_exists($compiler->smarty->registered_objects[$tag][0], $method)) { + // convert attributes into parameter array string + if ($compiler->smarty->registered_objects[$tag][2]) { + $_paramsArray = array(); + foreach ($_attr as $_key => $_value) { + if (is_int($_key)) { + $_paramsArray[] = "$_key=>$_value"; + } else { + $_paramsArray[] = "'$_key'=>$_value"; + } } + $_params = 'array(' . implode(",", $_paramsArray) . ')'; + $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params},\$_smarty_tpl)"; + } else { + $_params = implode(",", $_attr); + $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params})"; } - $_params = 'array(' . implode(",", $_paramsArray) . ')'; - $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params},\$_smarty_tpl)"; } else { - $_params = implode(",", $_attr); - $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params})"; + // object property + $return = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}"; } + if (empty($_assign)) { // This tag does create output $compiler->has_output = true;