enabled registration of class-methods as callbacks for the

register_*-functions

use: array('classname', 'method_name')) as callback
This commit is contained in:
messju
2003-07-31 13:51:28 +00:00
parent a76d8f6a1a
commit 19f709da5a
3 changed files with 11 additions and 8 deletions

2
NEWS
View File

@@ -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 filepath caching (Monte)
- added optional assign-attribute to {capture}-tag (messju) - added optional assign-attribute to {capture}-tag (messju)
- added $cacheable-parameter to register_compiler_function() (messju) - added $cacheable-parameter to register_compiler_function() (messju)

View File

@@ -855,11 +855,11 @@ class Smarty
*/ */
function register_resource($type, $functions) function register_resource($type, $functions)
{ {
if (sizeof($functions)<5) { if (count($functions)==4) {
$this->_plugins['resource'][$type] = $this->_plugins['resource'][$type] =
array($functions, false); array($functions, false);
} elseif (sizeof($functions)==5 && is_object($functions[0])) { } elseif (count($functions)==5) {
$this->_plugins['resource'][$type] = $this->_plugins['resource'][$type] =
array(array(array(&$functions[0], $functions[1]) array(array(array(&$functions[0], $functions[1])
,array(&$functions[0], $functions[2]) ,array(&$functions[0], $functions[2])
@@ -1608,7 +1608,6 @@ class Smarty
function _fetch_resource_info(&$params) function _fetch_resource_info(&$params)
{ {
if(!isset($params['get_source'])) { $params['get_source'] = true; } if(!isset($params['get_source'])) { $params['get_source'] = true; }
if(!isset($params['quiet'])) { $params['quiet'] = false; } if(!isset($params['quiet'])) { $params['quiet'] = false; }
@@ -1917,7 +1916,7 @@ class Smarty
function _plugin_implementation_exists($function) function _plugin_implementation_exists($function)
{ {
return (is_array($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);
} }

View File

@@ -1961,8 +1961,10 @@ class Smarty_Compiler extends Smarty {
if (isset($this->_plugins[$type][$name])) { if (isset($this->_plugins[$type][$name])) {
/* plugin loaded */ /* plugin loaded */
if (is_array($this->_plugins[$type][$name][0])) { if (is_array($this->_plugins[$type][$name][0])) {
/* method callback */ return ((is_object($this->_plugins[$type][$name][0][0])) ?
return "\$this->_plugins['$type']['$name'][0][0]->".$this->_plugins[$type][$name][0][1]; "\$this->_plugins['$type']['$name'][0][0]->" /* method callback */
: (string)($this->_plugins[$type][$name][0][0]).'::' /* class callback */
). $this->_plugins[$type][$name][0][1];
} else { } else {
/* function callback */ /* function callback */