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

@@ -41,7 +41,7 @@ class ForClose extends Base {
if ($nocache_pushed) { if ($nocache_pushed) {
// pop the pushed virtual nocache tag // pop the pushed virtual nocache tag
$this->closeTag('nocache'); $this->closeTag($compiler, 'nocache');
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }

View File

@@ -90,7 +90,7 @@ class ForTag extends Base {
if ($compiler->tag_nocache) { if ($compiler->tag_nocache) {
// push a {nocache} tag onto the stack to prevent caching of this for loop // push a {nocache} tag onto the stack to prevent caching of this for loop
$this->openTag('nocache'); $this->openTag($compiler, 'nocache');
} }
$this->openTag($compiler, 'for', ['for', $compiler->tag_nocache]); $this->openTag($compiler, 'for', ['for', $compiler->tag_nocache]);

View File

@@ -36,7 +36,7 @@ class ForeachClose extends Base {
if ($nocache_pushed) { if ($nocache_pushed) {
// pop the pushed virtual nocache tag // pop the pushed virtual nocache tag
$this->closeTag('nocache'); $this->closeTag($compiler, 'nocache');
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }

View File

@@ -184,7 +184,7 @@ class ForeachTag extends ForeachSection {
if ($compiler->tag_nocache) { if ($compiler->tag_nocache) {
// push a {nocache} tag onto the stack to prevent caching of this block // push a {nocache} tag onto the stack to prevent caching of this block
$this->openTag('nocache'); $this->openTag($compiler, 'nocache');
} }
// Register tag // Register tag

View File

@@ -34,7 +34,7 @@ class IfClose extends Base {
if ($nocache_pushed) { if ($nocache_pushed) {
// pop the pushed virtual nocache tag // pop the pushed virtual nocache tag
$this->closeTag('nocache'); $this->closeTag($compiler, 'nocache');
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }

View File

@@ -26,7 +26,7 @@ class IfTag extends Base {
if ($compiler->tag_nocache) { if ($compiler->tag_nocache) {
// push a {nocache} tag onto the stack to prevent caching of this block // push a {nocache} tag onto the stack to prevent caching of this block
$this->openTag('nocache'); $this->openTag($compiler, 'nocache');
} }
$this->openTag($compiler, 'if', [1, $compiler->tag_nocache]); $this->openTag($compiler, 'if', [1, $compiler->tag_nocache]);

View File

@@ -35,7 +35,7 @@ class WhileClose extends Base {
if ($nocache_pushed) { if ($nocache_pushed) {
// pop the pushed virtual nocache tag // pop the pushed virtual nocache tag
$this->closeTag('nocache'); $this->closeTag($compiler, 'nocache');
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }

View File

@@ -27,7 +27,7 @@ class WhileTag extends Base {
if ($compiler->tag_nocache) { if ($compiler->tag_nocache) {
// push a {nocache} tag onto the stack to prevent caching of this block // push a {nocache} tag onto the stack to prevent caching of this block
$this->openTag('nocache'); $this->openTag($compiler, 'nocache');
} }
$this->openTag($compiler, 'while', $compiler->tag_nocache); $this->openTag($compiler, 'while', $compiler->tag_nocache);

View File

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

View File

@@ -769,7 +769,7 @@ class Smarty extends \Smarty\TemplateBase
public function registerPlugin($type, $name, $callback, $cacheable = true) { public function registerPlugin($type, $name, $callback, $cacheable = true) {
if (isset($this->registered_plugins[$type][$name])) { if (isset($this->registered_plugins[$type][$name])) {
throw new Exception("Plugin tag '{$name}' already registered"); throw new Exception("Plugin tag '{$name}' already registered");
} elseif (!is_callable($callback)) { } elseif (!is_callable($callback) && !class_exists($callback)) {
throw new Exception("Plugin '{$name}' not callable"); throw new Exception("Plugin '{$name}' not callable");
} else { } else {
$this->registered_plugins[$type][$name] = [$callback, (bool)$cacheable]; $this->registered_plugins[$type][$name] = [$callback, (bool)$cacheable];