remove Smarty::_plugin_implementation_exists() - use php's native

is_callable()
This commit is contained in:
messju
2003-09-12 13:40:53 +00:00
parent e2c21493b8
commit ad7803b89a
6 changed files with 10 additions and 19 deletions

1
NEWS
View File

@@ -1,3 +1,4 @@
- remove Smarty::_plugin_implementation_exists() - use is_callable() (messju)
- ignore {strip}/{/strip) inside {strip}-blocks (messju) - ignore {strip}/{/strip) inside {strip}-blocks (messju)
- fixed removal of leading/trailing newlines in {strip}-blocks (messju) - fixed removal of leading/trailing newlines in {strip}-blocks (messju)
- fixed proper escaping of " and ' with escape:javascript (messju) - fixed proper escaping of " and ' with escape:javascript (messju)

View File

@@ -1667,7 +1667,7 @@ class Smarty
if (!$_return) { if (!$_return) {
// see if we can get a template with the default template handler // see if we can get a template with the default template handler
if (!empty($this->default_template_handler_func)) { if (!empty($this->default_template_handler_func)) {
if (!$this->_plugin_implementation_exists($this->default_template_handler_func)) { if (!is_callable($this->default_template_handler_func)) {
$this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist."); $this->trigger_error("default template handler function \"$this->default_template_handler_func\" doesn't exist.");
} else { } else {
$_return = call_user_func_array( $_return = call_user_func_array(
@@ -1934,16 +1934,6 @@ class Smarty
} }
} }
/**
* check if the function or method exists
* @return bool
*/
function _plugin_implementation_exists($function)
{
return (is_array($function)) ?
method_exists($function[0], $function[1]) || (in_array(strtolower($function[1]), (array)get_class_methods($function[0]))) : function_exists($function);
}
/** /**
* callback function for preg_replace, to call a non-cacheable block * callback function for preg_replace, to call a non-cacheable block

View File

@@ -250,7 +250,7 @@ class Smarty_Compiler extends Smarty {
if (count($this->_plugins['prefilter']) > 0) { if (count($this->_plugins['prefilter']) > 0) {
foreach ($this->_plugins['prefilter'] as $filter_name => $prefilter) { foreach ($this->_plugins['prefilter'] as $filter_name => $prefilter) {
if ($prefilter === false) continue; if ($prefilter === false) continue;
if ($prefilter[3] || $this->_plugin_implementation_exists($prefilter[0])) { if ($prefilter[3] || is_callable($prefilter[0])) {
$source_content = call_user_func_array($prefilter[0], $source_content = call_user_func_array($prefilter[0],
array($source_content, &$this)); array($source_content, &$this));
$this->_plugins['prefilter'][$filter_name][3] = true; $this->_plugins['prefilter'][$filter_name][3] = true;
@@ -360,7 +360,7 @@ class Smarty_Compiler extends Smarty {
if (count($this->_plugins['postfilter']) > 0) { if (count($this->_plugins['postfilter']) > 0) {
foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) { foreach ($this->_plugins['postfilter'] as $filter_name => $postfilter) {
if ($postfilter === false) continue; if ($postfilter === false) continue;
if ($postfilter[3] || $this->_plugin_implementation_exists($postfilter[0])) { if ($postfilter[3] || is_callable($postfilter[0])) {
$compiled_content = call_user_func_array($postfilter[0], $compiled_content = call_user_func_array($postfilter[0],
array($compiled_content, &$this)); array($compiled_content, &$this));
$this->_plugins['postfilter'][$filter_name][3] = true; $this->_plugins['postfilter'][$filter_name][3] = true;
@@ -571,7 +571,7 @@ class Smarty_Compiler extends Smarty {
if (isset($this->_plugins['compiler'][$tag_command])) { if (isset($this->_plugins['compiler'][$tag_command])) {
$found = true; $found = true;
$plugin_func = $this->_plugins['compiler'][$tag_command][0]; $plugin_func = $this->_plugins['compiler'][$tag_command][0];
if (!$this->_plugin_implementation_exists($plugin_func)) { if (!is_callable($plugin_func)) {
$message = "compiler function '$tag_command' is not implemented"; $message = "compiler function '$tag_command' is not implemented";
$have_function = false; $have_function = false;
} }
@@ -586,7 +586,7 @@ class Smarty_Compiler extends Smarty {
include_once $plugin_file; include_once $plugin_file;
$plugin_func = 'smarty_compiler_' . $tag_command; $plugin_func = 'smarty_compiler_' . $tag_command;
if (!$this->_plugin_implementation_exists($plugin_func)) { if (!is_callable($plugin_func)) {
$message = "plugin function $plugin_func() not found in $plugin_file\n"; $message = "plugin function $plugin_func() not found in $plugin_file\n";
$have_function = false; $have_function = false;
} else { } else {
@@ -646,7 +646,7 @@ class Smarty_Compiler extends Smarty {
if (isset($this->_plugins['block'][$tag_command])) { if (isset($this->_plugins['block'][$tag_command])) {
$found = true; $found = true;
$plugin_func = $this->_plugins['block'][$tag_command][0]; $plugin_func = $this->_plugins['block'][$tag_command][0];
if (!$this->_plugin_implementation_exists($plugin_func)) { if (!is_callable($plugin_func)) {
$message = "block function '$tag_command' is not implemented"; $message = "block function '$tag_command' is not implemented";
$have_function = false; $have_function = false;
} }

View File

@@ -40,7 +40,7 @@ function smarty_core_get_php_resource(&$params, &$smarty)
} }
} else if ($params['resource_type'] != 'file') { } else if ($params['resource_type'] != 'file') {
$_template_source = null; $_template_source = null;
$_readable = $smarty->_plugin_implementation_exists($smarty->_plugins['resource'][$params['resource_type']][0][0]) $_readable = is_callable($smarty->_plugins['resource'][$params['resource_type']][0][0])
&& call_user_func_array($smarty->_plugins['resource'][$params['resource_type']][0][0], && call_user_func_array($smarty->_plugins['resource'][$params['resource_type']][0][0],
array($params['resource_name'], &$_template_source, &$smarty)); array($params['resource_name'], &$_template_source, &$smarty));
} }

View File

@@ -32,7 +32,7 @@ function smarty_core_load_plugins($params, &$smarty)
*/ */
if (isset($_plugin)) { if (isset($_plugin)) {
if (empty($_plugin[3])) { if (empty($_plugin[3])) {
if (!$smarty->_plugin_implementation_exists($_plugin[0])) { if (!is_callable($_plugin[0])) {
$smarty->_trigger_fatal_error("[plugin] $_type '$_name' is not implemented", $_tpl_file, $_tpl_line, __FILE__, __LINE__); $smarty->_trigger_fatal_error("[plugin] $_type '$_name' is not implemented", $_tpl_file, $_tpl_line, __FILE__, __LINE__);
} else { } else {
$_plugin[1] = $_tpl_file; $_plugin[1] = $_tpl_file;

View File

@@ -27,7 +27,7 @@ function smarty_core_load_resource_plugin($params, &$smarty)
if (!$_plugin[1] && count($_plugin[0])) { if (!$_plugin[1] && count($_plugin[0])) {
$_plugin[1] = true; $_plugin[1] = true;
foreach ($_plugin[0] as $_plugin_func) { foreach ($_plugin[0] as $_plugin_func) {
if (!$smarty->_plugin_implementation_exists($_plugin_func)) { if (!is_callable($_plugin_func)) {
$_plugin[1] = false; $_plugin[1] = false;
break; break;
} }