From 19f709da5a92140107446e3b53f9d5164c30e74a Mon Sep 17 00:00:00 2001 From: messju Date: Thu, 31 Jul 2003 13:51:28 +0000 Subject: [PATCH] enabled registration of class-methods as callbacks for the register_*-functions use: array('classname', 'method_name')) as callback --- NEWS | 2 ++ libs/Smarty.class.php | 9 ++++----- libs/Smarty_Compiler.class.php | 8 +++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index f00276c5..af4b9d46 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ + - enabled registration of class-methods as callbacks for the register_*- + functions (use: array('classname', 'method_name')) as callback) (messju) - added filepath caching (Monte) - added optional assign-attribute to {capture}-tag (messju) - added $cacheable-parameter to register_compiler_function() (messju) diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index c07033de..ad32976d 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -855,11 +855,11 @@ class Smarty */ function register_resource($type, $functions) { - if (sizeof($functions)<5) { + if (count($functions)==4) { $this->_plugins['resource'][$type] = array($functions, false); - } elseif (sizeof($functions)==5 && is_object($functions[0])) { + } elseif (count($functions)==5) { $this->_plugins['resource'][$type] = array(array(array(&$functions[0], $functions[1]) ,array(&$functions[0], $functions[2]) @@ -1608,10 +1608,9 @@ class Smarty function _fetch_resource_info(&$params) { - if(!isset($params['get_source'])) { $params['get_source'] = true; } if(!isset($params['quiet'])) { $params['quiet'] = false; } - + $_return = false; $_params = array('resource_name' => $params['resource_name']) ; if ($this->_parse_resource_name($_params)) { @@ -1917,7 +1916,7 @@ class Smarty function _plugin_implementation_exists($function) { return (is_array($function)) ? - method_exists($function[0], $function[1]) : function_exists($function); + method_exists($function[0], $function[1]) || (in_array(strtolower($function[1]), (array)get_class_methods($function[0]))) : function_exists($function); } diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 4b5699ec..2ff89670 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -1961,9 +1961,11 @@ class Smarty_Compiler extends Smarty { if (isset($this->_plugins[$type][$name])) { /* plugin loaded */ if (is_array($this->_plugins[$type][$name][0])) { - /* method callback */ - return "\$this->_plugins['$type']['$name'][0][0]->".$this->_plugins[$type][$name][0][1]; - + return ((is_object($this->_plugins[$type][$name][0][0])) ? + "\$this->_plugins['$type']['$name'][0][0]->" /* method callback */ + : (string)($this->_plugins[$type][$name][0][0]).'::' /* class callback */ + ). $this->_plugins[$type][$name][0][1]; + } else { /* function callback */ return $this->_plugins[$type][$name][0];