From 41054cfb05f816203e19543475031f2dbb52c157 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Wed, 4 Jan 2023 12:16:10 +0100 Subject: [PATCH] Fixed DefaultPluginHandlerTest for function plugins (blocks still break) --- src/Compile/{Tag => }/Base.php | 5 +- src/Compile/BlockCompiler.php | 2 +- ...lerInterface.php => CompilerInterface.php} | 4 +- .../DefaultHandlerFunctionCallCompiler.php | 55 +++++++++++++++++++ src/Compile/FunctionCallCompiler.php | 2 - src/Compile/ModifierCompiler.php | 2 +- src/Compile/ObjectMethodCallCompiler.php | 2 +- src/Compile/PrintExpressionCompiler.php | 2 +- src/Compile/SpecialVariableCompiler.php | 2 +- src/Compile/Tag/Assign.php | 1 + src/Compile/Tag/BCPluginWrapper.php | 2 + src/Compile/Tag/BreakTag.php | 2 + src/Compile/Tag/Call.php | 2 + src/Compile/Tag/Capture.php | 2 + src/Compile/Tag/CaptureClose.php | 2 + src/Compile/Tag/Child.php | 2 + src/Compile/Tag/ConfigLoad.php | 1 + src/Compile/Tag/Debug.php | 2 + src/Compile/Tag/ElseIfTag.php | 2 + src/Compile/Tag/ElseTag.php | 2 + src/Compile/Tag/EvalTag.php | 2 + src/Compile/Tag/ForClose.php | 2 + src/Compile/Tag/ForElse.php | 2 + src/Compile/Tag/ForTag.php | 2 + src/Compile/Tag/ForeachClose.php | 2 + src/Compile/Tag/ForeachElse.php | 2 + src/Compile/Tag/ForeachSection.php | 2 + src/Compile/Tag/FunctionClose.php | 2 + src/Compile/Tag/FunctionTag.php | 2 + src/Compile/Tag/IfClose.php | 2 + src/Compile/Tag/IfTag.php | 2 + src/Compile/Tag/IncludeTag.php | 1 + src/Compile/Tag/Inheritance.php | 2 + src/Compile/Tag/Ldelim.php | 2 + src/Compile/Tag/MakeNocache.php | 2 + src/Compile/Tag/Nocache.php | 2 + src/Compile/Tag/NocacheClose.php | 2 + src/Compile/Tag/SectionClose.php | 2 + src/Compile/Tag/SectionElse.php | 2 + src/Compile/Tag/Setfilter.php | 2 + src/Compile/Tag/SetfilterClose.php | 2 + src/Compile/Tag/WhileClose.php | 2 + src/Compile/Tag/WhileTag.php | 2 + src/Compiler/Template.php | 7 ++- src/Extension/BCPluginsAdapter.php | 2 +- src/Extension/Base.php | 2 +- src/Extension/CoreExtension.php | 2 +- src/Extension/ExtensionInterface.php | 2 +- src/Smarty.php | 24 ++++++++ .../PHPunitplugins/compiler.test.php | 2 +- .../PHPunitplugins/compiler.testclose.php | 2 +- .../compiler.getparamsshort.php | 2 +- 52 files changed, 165 insertions(+), 21 deletions(-) rename src/Compile/{Tag => }/Base.php (98%) rename src/Compile/{Tag/TagCompilerInterface.php => CompilerInterface.php} (90%) create mode 100644 src/Compile/DefaultHandlerFunctionCallCompiler.php diff --git a/src/Compile/Tag/Base.php b/src/Compile/Base.php similarity index 98% rename from src/Compile/Tag/Base.php rename to src/Compile/Base.php index afb75533..5a2a58d1 100644 --- a/src/Compile/Tag/Base.php +++ b/src/Compile/Base.php @@ -3,14 +3,15 @@ * Smarty Internal Compile Plugin Base * @author Uwe Tews */ -namespace Smarty\Compile\Tag; +namespace Smarty\Compile; + /** * This class does extend all internal compile plugins * * @package Smarty * @subpackage Compiler */ -abstract class Base implements TagCompilerInterface { +abstract class Base implements CompilerInterface { /** * Array of names of required attribute required by tag diff --git a/src/Compile/BlockCompiler.php b/src/Compile/BlockCompiler.php index 47423ea6..3855d52b 100644 --- a/src/Compile/BlockCompiler.php +++ b/src/Compile/BlockCompiler.php @@ -10,7 +10,7 @@ namespace Smarty\Compile; -use Smarty\Compile\Tag\Base; +use Smarty\Compile\Base; /** * Smarty Internal Plugin Compile Block Plugin Class diff --git a/src/Compile/Tag/TagCompilerInterface.php b/src/Compile/CompilerInterface.php similarity index 90% rename from src/Compile/Tag/TagCompilerInterface.php rename to src/Compile/CompilerInterface.php index da27bfe4..2d143fa1 100644 --- a/src/Compile/Tag/TagCompilerInterface.php +++ b/src/Compile/CompilerInterface.php @@ -1,6 +1,6 @@ getAttributes($compiler, $args); + unset($_attr['nocache']); + + // convert attributes into parameter array string + + $_paramsArray = []; + foreach ($_attr as $_key => $_value) { + if (is_int($_key)) { + $_paramsArray[] = "$_key=>$_value"; + } else { + $_paramsArray[] = "'$_key'=>$_value"; + } + } + $_params = 'array(' . implode(',', $_paramsArray) . ')'; + + $output = "\$_smarty_tpl->smarty->runPluginFromDefaultHandler(" . var_export($function, true) . + ",'function',$_params, \$_smarty_tpl)"; + + if (!empty($parameter['modifierlist'])) { + $output = $compiler->compileModifier($parameter['modifierlist'], $output); + } + return "\n"; + } +} \ No newline at end of file diff --git a/src/Compile/FunctionCallCompiler.php b/src/Compile/FunctionCallCompiler.php index 7a700b2a..65906535 100644 --- a/src/Compile/FunctionCallCompiler.php +++ b/src/Compile/FunctionCallCompiler.php @@ -10,9 +10,7 @@ namespace Smarty\Compile; -use Smarty\Compile\Tag\Base; use Smarty\Compiler\Template; -use Smarty\Smarty; /** * Smarty Internal Plugin Compile Registered Function Class diff --git a/src/Compile/ModifierCompiler.php b/src/Compile/ModifierCompiler.php index 59e7b969..c15e45ba 100644 --- a/src/Compile/ModifierCompiler.php +++ b/src/Compile/ModifierCompiler.php @@ -10,7 +10,7 @@ namespace Smarty\Compile; -use Smarty\Compile\Tag\Base; +use Smarty\Compile\Base; /** * Smarty Internal Plugin Compile Modifier Class diff --git a/src/Compile/ObjectMethodCallCompiler.php b/src/Compile/ObjectMethodCallCompiler.php index 3c73d2fc..76ada5c3 100644 --- a/src/Compile/ObjectMethodCallCompiler.php +++ b/src/Compile/ObjectMethodCallCompiler.php @@ -10,7 +10,7 @@ namespace Smarty\Compile; -use Smarty\Compile\Tag\Base; +use Smarty\Compile\Base; /** * Smarty Internal Plugin Compile Object Function Class diff --git a/src/Compile/PrintExpressionCompiler.php b/src/Compile/PrintExpressionCompiler.php index e5cc2dbc..89c42973 100644 --- a/src/Compile/PrintExpressionCompiler.php +++ b/src/Compile/PrintExpressionCompiler.php @@ -10,7 +10,7 @@ namespace Smarty\Compile; -use Smarty\Compile\Tag\Base; +use Smarty\Compile\Base; use Smarty\Compiler\BaseCompiler; /** diff --git a/src/Compile/SpecialVariableCompiler.php b/src/Compile/SpecialVariableCompiler.php index 72de08c1..b838e67a 100644 --- a/src/Compile/SpecialVariableCompiler.php +++ b/src/Compile/SpecialVariableCompiler.php @@ -10,7 +10,7 @@ namespace Smarty\Compile; -use Smarty\Compile\Tag\Base; +use Smarty\Compile\Base; use Smarty\Compile\Tag\Capture; use Smarty\Compile\Tag\ForeachTag; use Smarty\Compile\Tag\Section; diff --git a/src/Compile/Tag/Assign.php b/src/Compile/Tag/Assign.php index 83fe3da0..06f5fba7 100644 --- a/src/Compile/Tag/Assign.php +++ b/src/Compile/Tag/Assign.php @@ -2,6 +2,7 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; use Smarty\Smarty; /** diff --git a/src/Compile/Tag/BCPluginWrapper.php b/src/Compile/Tag/BCPluginWrapper.php index a34d0bea..58f11166 100644 --- a/src/Compile/Tag/BCPluginWrapper.php +++ b/src/Compile/Tag/BCPluginWrapper.php @@ -2,6 +2,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + class BCPluginWrapper extends Base { private $callback; diff --git a/src/Compile/Tag/BreakTag.php b/src/Compile/Tag/BreakTag.php index 8c22c6a5..0850fa87 100644 --- a/src/Compile/Tag/BreakTag.php +++ b/src/Compile/Tag/BreakTag.php @@ -10,6 +10,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Break Class * diff --git a/src/Compile/Tag/Call.php b/src/Compile/Tag/Call.php index 00c42ced..af0ff75f 100644 --- a/src/Compile/Tag/Call.php +++ b/src/Compile/Tag/Call.php @@ -10,6 +10,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Function_Call Class * diff --git a/src/Compile/Tag/Capture.php b/src/Compile/Tag/Capture.php index 460786fb..b58b3ba4 100644 --- a/src/Compile/Tag/Capture.php +++ b/src/Compile/Tag/Capture.php @@ -2,6 +2,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Capture Class * diff --git a/src/Compile/Tag/CaptureClose.php b/src/Compile/Tag/CaptureClose.php index 9455bcfa..2df4d3a9 100644 --- a/src/Compile/Tag/CaptureClose.php +++ b/src/Compile/Tag/CaptureClose.php @@ -10,6 +10,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Captureclose Class * diff --git a/src/Compile/Tag/Child.php b/src/Compile/Tag/Child.php index f3b5c650..6c1dc925 100644 --- a/src/Compile/Tag/Child.php +++ b/src/Compile/Tag/Child.php @@ -10,6 +10,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Child Class * diff --git a/src/Compile/Tag/ConfigLoad.php b/src/Compile/Tag/ConfigLoad.php index c31778e4..809d7908 100644 --- a/src/Compile/Tag/ConfigLoad.php +++ b/src/Compile/Tag/ConfigLoad.php @@ -10,6 +10,7 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; use Smarty\Smarty; /** diff --git a/src/Compile/Tag/Debug.php b/src/Compile/Tag/Debug.php index 42c9a12e..10ba31fc 100644 --- a/src/Compile/Tag/Debug.php +++ b/src/Compile/Tag/Debug.php @@ -11,6 +11,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Debug Class * diff --git a/src/Compile/Tag/ElseIfTag.php b/src/Compile/Tag/ElseIfTag.php index ec5f1605..131211ab 100644 --- a/src/Compile/Tag/ElseIfTag.php +++ b/src/Compile/Tag/ElseIfTag.php @@ -2,6 +2,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile ElseIf Class * diff --git a/src/Compile/Tag/ElseTag.php b/src/Compile/Tag/ElseTag.php index 8633ae19..3cf8f066 100644 --- a/src/Compile/Tag/ElseTag.php +++ b/src/Compile/Tag/ElseTag.php @@ -2,6 +2,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Else Class * diff --git a/src/Compile/Tag/EvalTag.php b/src/Compile/Tag/EvalTag.php index fca6b6f4..a7649f23 100644 --- a/src/Compile/Tag/EvalTag.php +++ b/src/Compile/Tag/EvalTag.php @@ -10,6 +10,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Eval Class * diff --git a/src/Compile/Tag/ForClose.php b/src/Compile/Tag/ForClose.php index 810f59dd..292f0b46 100644 --- a/src/Compile/Tag/ForClose.php +++ b/src/Compile/Tag/ForClose.php @@ -10,6 +10,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Forclose Class * diff --git a/src/Compile/Tag/ForElse.php b/src/Compile/Tag/ForElse.php index 1fa22b02..6df6a8cb 100644 --- a/src/Compile/Tag/ForElse.php +++ b/src/Compile/Tag/ForElse.php @@ -2,6 +2,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Forelse Class * diff --git a/src/Compile/Tag/ForTag.php b/src/Compile/Tag/ForTag.php index 0164996b..5832bb1d 100644 --- a/src/Compile/Tag/ForTag.php +++ b/src/Compile/Tag/ForTag.php @@ -2,6 +2,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile For Class * diff --git a/src/Compile/Tag/ForeachClose.php b/src/Compile/Tag/ForeachClose.php index d620f496..33981499 100644 --- a/src/Compile/Tag/ForeachClose.php +++ b/src/Compile/Tag/ForeachClose.php @@ -10,6 +10,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Foreachclose Class * diff --git a/src/Compile/Tag/ForeachElse.php b/src/Compile/Tag/ForeachElse.php index cb89fb01..a9df6a47 100644 --- a/src/Compile/Tag/ForeachElse.php +++ b/src/Compile/Tag/ForeachElse.php @@ -2,6 +2,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Foreachelse Class * diff --git a/src/Compile/Tag/ForeachSection.php b/src/Compile/Tag/ForeachSection.php index f127b4b9..588c128d 100644 --- a/src/Compile/Tag/ForeachSection.php +++ b/src/Compile/Tag/ForeachSection.php @@ -10,6 +10,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile ForeachSection Class * diff --git a/src/Compile/Tag/FunctionClose.php b/src/Compile/Tag/FunctionClose.php index a343fdee..9cee992f 100644 --- a/src/Compile/Tag/FunctionClose.php +++ b/src/Compile/Tag/FunctionClose.php @@ -10,6 +10,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Functionclose Class * diff --git a/src/Compile/Tag/FunctionTag.php b/src/Compile/Tag/FunctionTag.php index f9a506f3..b77cf6f4 100644 --- a/src/Compile/Tag/FunctionTag.php +++ b/src/Compile/Tag/FunctionTag.php @@ -2,6 +2,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Function Class * diff --git a/src/Compile/Tag/IfClose.php b/src/Compile/Tag/IfClose.php index 1fcd12d8..1a4af678 100644 --- a/src/Compile/Tag/IfClose.php +++ b/src/Compile/Tag/IfClose.php @@ -10,6 +10,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Ifclose Class * diff --git a/src/Compile/Tag/IfTag.php b/src/Compile/Tag/IfTag.php index 6032cc72..f6c9495f 100644 --- a/src/Compile/Tag/IfTag.php +++ b/src/Compile/Tag/IfTag.php @@ -2,6 +2,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile If Class * diff --git a/src/Compile/Tag/IncludeTag.php b/src/Compile/Tag/IncludeTag.php index 60e29098..f0c8acff 100644 --- a/src/Compile/Tag/IncludeTag.php +++ b/src/Compile/Tag/IncludeTag.php @@ -10,6 +10,7 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; use Smarty\Compiler\Template; use Smarty\Smarty; use Smarty\Template\Compiled; diff --git a/src/Compile/Tag/Inheritance.php b/src/Compile/Tag/Inheritance.php index a058b67b..b6064ee6 100644 --- a/src/Compile/Tag/Inheritance.php +++ b/src/Compile/Tag/Inheritance.php @@ -2,6 +2,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Shared Inheritance * Shared methods for {extends} and {block} tags diff --git a/src/Compile/Tag/Ldelim.php b/src/Compile/Tag/Ldelim.php index 7e9ab5f1..2c9328a8 100644 --- a/src/Compile/Tag/Ldelim.php +++ b/src/Compile/Tag/Ldelim.php @@ -10,6 +10,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Ldelim Class * diff --git a/src/Compile/Tag/MakeNocache.php b/src/Compile/Tag/MakeNocache.php index 29ce01db..36f3c5b2 100644 --- a/src/Compile/Tag/MakeNocache.php +++ b/src/Compile/Tag/MakeNocache.php @@ -10,6 +10,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Make_Nocache Class * diff --git a/src/Compile/Tag/Nocache.php b/src/Compile/Tag/Nocache.php index 457b8afc..22f0db54 100644 --- a/src/Compile/Tag/Nocache.php +++ b/src/Compile/Tag/Nocache.php @@ -2,6 +2,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Nocache Class * diff --git a/src/Compile/Tag/NocacheClose.php b/src/Compile/Tag/NocacheClose.php index b5712ed1..f1569576 100644 --- a/src/Compile/Tag/NocacheClose.php +++ b/src/Compile/Tag/NocacheClose.php @@ -10,6 +10,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Nocacheclose Class * diff --git a/src/Compile/Tag/SectionClose.php b/src/Compile/Tag/SectionClose.php index ebaa6877..1aede5d6 100644 --- a/src/Compile/Tag/SectionClose.php +++ b/src/Compile/Tag/SectionClose.php @@ -10,6 +10,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Sectionclose Class * diff --git a/src/Compile/Tag/SectionElse.php b/src/Compile/Tag/SectionElse.php index a2c8242d..fad50279 100644 --- a/src/Compile/Tag/SectionElse.php +++ b/src/Compile/Tag/SectionElse.php @@ -2,6 +2,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Sectionelse Class * diff --git a/src/Compile/Tag/Setfilter.php b/src/Compile/Tag/Setfilter.php index c58d7322..f828480c 100644 --- a/src/Compile/Tag/Setfilter.php +++ b/src/Compile/Tag/Setfilter.php @@ -2,6 +2,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Setfilter Class * diff --git a/src/Compile/Tag/SetfilterClose.php b/src/Compile/Tag/SetfilterClose.php index d666f59e..4626da24 100644 --- a/src/Compile/Tag/SetfilterClose.php +++ b/src/Compile/Tag/SetfilterClose.php @@ -10,6 +10,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Setfilterclose Class * diff --git a/src/Compile/Tag/WhileClose.php b/src/Compile/Tag/WhileClose.php index 6b65f247..3983e395 100644 --- a/src/Compile/Tag/WhileClose.php +++ b/src/Compile/Tag/WhileClose.php @@ -10,6 +10,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile Whileclose Class * diff --git a/src/Compile/Tag/WhileTag.php b/src/Compile/Tag/WhileTag.php index 35f3d8a3..df12f1f5 100644 --- a/src/Compile/Tag/WhileTag.php +++ b/src/Compile/Tag/WhileTag.php @@ -2,6 +2,8 @@ namespace Smarty\Compile\Tag; +use Smarty\Compile\Base; + /** * Smarty Internal Plugin Compile While Class * diff --git a/src/Compiler/Template.php b/src/Compiler/Template.php index 10bdd7d3..96b177c2 100644 --- a/src/Compiler/Template.php +++ b/src/Compiler/Template.php @@ -11,6 +11,7 @@ namespace Smarty\Compiler; use Smarty\Compile\BlockCompiler; +use Smarty\Compile\DefaultHandlerFunctionCallCompiler; use Smarty\Compile\ModifierCompiler; use Smarty\Compile\ObjectMethodBlockCompiler; use Smarty\Compile\ObjectMethodCallCompiler; @@ -634,9 +635,9 @@ class Template extends BaseCompiler { * * @param string $tag tag name * - * @return ?\Smarty\Compile\Tag\TagCompilerInterface tag compiler object or null if not found or untrusted by security policy + * @return ?\Smarty\Compile\CompilerInterface tag compiler object or null if not found or untrusted by security policy */ - public function getTagCompiler($tag): ?\Smarty\Compile\Tag\TagCompilerInterface { + public function getTagCompiler($tag): ?\Smarty\Compile\CompilerInterface { if (isset($this->smarty->security_policy) && !$this->smarty->security_policy->isTrustedTag($tag, $this)) { return null; @@ -1268,7 +1269,7 @@ class Template extends BaseCompiler { } if ($this->getPluginFromDefaultHandler($tag, Smarty::PLUGIN_FUNCTION)) { - $compiler = new FunctionCallCompiler(); + $compiler = new DefaultHandlerFunctionCallCompiler(); return $compiler->compile($args, $this, $parameter, $tag, $base_tag); } diff --git a/src/Extension/BCPluginsAdapter.php b/src/Extension/BCPluginsAdapter.php index d9e9b262..4234ed05 100644 --- a/src/Extension/BCPluginsAdapter.php +++ b/src/Extension/BCPluginsAdapter.php @@ -27,7 +27,7 @@ class BCPluginsAdapter extends Base { return null; } - public function getTagCompiler(string $tag): ?\Smarty\Compile\Tag\TagCompilerInterface { + public function getTagCompiler(string $tag): ?\Smarty\Compile\CompilerInterface { $plugin = $this->findPlugin(\Smarty\Smarty::PLUGIN_COMPILER, $tag); if ($plugin === null) { diff --git a/src/Extension/Base.php b/src/Extension/Base.php index 1b363e95..b37b6acd 100644 --- a/src/Extension/Base.php +++ b/src/Extension/Base.php @@ -6,7 +6,7 @@ use Smarty\FunctionHandler\FunctionHandlerInterface; class Base implements ExtensionInterface { - public function getTagCompiler(string $tag): ?\Smarty\Compile\Tag\TagCompilerInterface { + public function getTagCompiler(string $tag): ?\Smarty\Compile\CompilerInterface { return null; } diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index 17b2b403..c5c919ff 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -3,7 +3,7 @@ namespace Smarty\Extension; class CoreExtension extends Base { - public function getTagCompiler(string $tag): ?\Smarty\Compile\Tag\TagCompilerInterface { + public function getTagCompiler(string $tag): ?\Smarty\Compile\CompilerInterface { switch ($tag) { case 'append': return new \Smarty\Compile\Tag\Append(); case 'assign': return new \Smarty\Compile\Tag\Assign(); diff --git a/src/Extension/ExtensionInterface.php b/src/Extension/ExtensionInterface.php index 791b8e3a..50752f5d 100644 --- a/src/Extension/ExtensionInterface.php +++ b/src/Extension/ExtensionInterface.php @@ -4,7 +4,7 @@ namespace Smarty\Extension; interface ExtensionInterface { - public function getTagCompiler(string $tag): ?\Smarty\Compile\Tag\TagCompilerInterface; + public function getTagCompiler(string $tag): ?\Smarty\Compile\CompilerInterface; public function getModifierCompiler(string $modifier): ?\Smarty\Compile\Modifier\ModifierCompilerInterface; diff --git a/src/Smarty.php b/src/Smarty.php index 230b4422..8285df3f 100644 --- a/src/Smarty.php +++ b/src/Smarty.php @@ -2103,6 +2103,30 @@ class Smarty extends \Smarty\TemplateBase return $this->default_plugin_handler_func; } + public function runPluginFromDefaultHandler($tag, $plugin_type, $params, \Smarty\Template $template) { + $defaultPluginHandlerFunc = $this->getDefaultPluginHandlerFunc(); + + $callback = null; + + // these are not used here + $script = null; + $cacheable = null; + + if (call_user_func_array( + $defaultPluginHandlerFunc, + [ + $tag, + $plugin_type, + null, // This used to pass $this->template, but this parameter has been removed in 5.0 + &$callback, + &$script, + &$cacheable, + ] + ) && $callback) { + return $callback($params, $template); + } + throw new Exception("Default plugin handler: Returned callback for '{$tag}' not callable at runtime"); + } /** * load a filter of specified type and name diff --git a/tests/UnitTests/TemplateSource/TagTests/CompilerPlugin/PHPunitplugins/compiler.test.php b/tests/UnitTests/TemplateSource/TagTests/CompilerPlugin/PHPunitplugins/compiler.test.php index 5fb9ff83..13ca0dee 100644 --- a/tests/UnitTests/TemplateSource/TagTests/CompilerPlugin/PHPunitplugins/compiler.test.php +++ b/tests/UnitTests/TemplateSource/TagTests/CompilerPlugin/PHPunitplugins/compiler.test.php @@ -1,7 +1,7 @@