Handle BC registered compilers and missed parameters for openTag and closeTag.

This commit is contained in:
Simon Wisselink
2023-01-23 12:08:36 +01:00
parent f1c3ac4395
commit ad2703dd75
10 changed files with 25 additions and 14 deletions

View File

@@ -3,6 +3,7 @@
namespace Smarty\Extension;
use Smarty\BlockHandler\BlockPluginWrapper;
use Smarty\Compile\CompilerInterface;
use Smarty\Compile\Modifier\BCPluginWrapper as ModifierCompilerPluginWrapper;
use Smarty\Compile\Tag\BCPluginWrapper as TagPluginWrapper;
use Smarty\Filter\FilterPluginWrapper;
@@ -34,9 +35,18 @@ class BCPluginsAdapter extends Base {
return null;
}
$callback = $plugin[0];
$cacheable = (bool) $plugin[1] ?? true;
return new TagPluginWrapper($callback, $cacheable);
if (is_callable($plugin[0])) {
$callback = $plugin[0];
$cacheable = (bool) $plugin[1] ?? true;
return new TagPluginWrapper($callback, $cacheable);
} elseif (class_exists($plugin[0])) {
$compiler = new $plugin[0];
if ($compiler instanceof CompilerInterface) {
return $compiler;
}
}
return null;
}
public function getFunctionHandler(string $functionName): ?\Smarty\FunctionHandler\FunctionHandlerInterface {
@@ -172,8 +182,9 @@ class BCPluginsAdapter extends Base {
$pluginName = $this->getPluginNameFromFilename($filename);
if ($pluginName !== null) {
require_once $filename;
if (function_exists($functionName = 'smarty_' . $type . '_' . $pluginName)) {
$this->smarty->registerPlugin($type, $pluginName, $functionName, true, []);
$functionOrClassName = 'smarty_' . $type . '_' . $pluginName;
if (function_exists($functionOrClassName) || class_exists($functionOrClassName)) {
$this->smarty->registerPlugin($type, $pluginName, $functionOrClassName, true, []);
}
}
}