mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 09:54:27 +02:00
Handle BC registered compilers and missed parameters for openTag and closeTag.
This commit is contained in:
@@ -41,7 +41,7 @@ class ForClose extends Base {
|
||||
|
||||
if ($nocache_pushed) {
|
||||
// pop the pushed virtual nocache tag
|
||||
$this->closeTag('nocache');
|
||||
$this->closeTag($compiler, 'nocache');
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
|
||||
|
@@ -90,7 +90,7 @@ class ForTag extends Base {
|
||||
|
||||
if ($compiler->tag_nocache) {
|
||||
// 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]);
|
||||
|
@@ -36,7 +36,7 @@ class ForeachClose extends Base {
|
||||
|
||||
if ($nocache_pushed) {
|
||||
// pop the pushed virtual nocache tag
|
||||
$this->closeTag('nocache');
|
||||
$this->closeTag($compiler, 'nocache');
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
|
||||
|
@@ -184,7 +184,7 @@ class ForeachTag extends ForeachSection {
|
||||
|
||||
if ($compiler->tag_nocache) {
|
||||
// push a {nocache} tag onto the stack to prevent caching of this block
|
||||
$this->openTag('nocache');
|
||||
$this->openTag($compiler, 'nocache');
|
||||
}
|
||||
|
||||
// Register tag
|
||||
|
@@ -34,7 +34,7 @@ class IfClose extends Base {
|
||||
|
||||
if ($nocache_pushed) {
|
||||
// pop the pushed virtual nocache tag
|
||||
$this->closeTag('nocache');
|
||||
$this->closeTag($compiler, 'nocache');
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
|
||||
|
@@ -26,7 +26,7 @@ class IfTag extends Base {
|
||||
|
||||
if ($compiler->tag_nocache) {
|
||||
// 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]);
|
||||
|
@@ -35,7 +35,7 @@ class WhileClose extends Base {
|
||||
|
||||
if ($nocache_pushed) {
|
||||
// pop the pushed virtual nocache tag
|
||||
$this->closeTag('nocache');
|
||||
$this->closeTag($compiler, 'nocache');
|
||||
$compiler->tag_nocache = true;
|
||||
}
|
||||
|
||||
|
@@ -27,7 +27,7 @@ class WhileTag extends Base {
|
||||
|
||||
if ($compiler->tag_nocache) {
|
||||
// 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);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
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, []);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -769,7 +769,7 @@ class Smarty extends \Smarty\TemplateBase
|
||||
public function registerPlugin($type, $name, $callback, $cacheable = true) {
|
||||
if (isset($this->registered_plugins[$type][$name])) {
|
||||
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");
|
||||
} else {
|
||||
$this->registered_plugins[$type][$name] = [$callback, (bool)$cacheable];
|
||||
|
Reference in New Issue
Block a user