Fixed DefaultPluginHandlerTest for function plugins (blocks still break)

This commit is contained in:
Simon Wisselink
2023-01-04 12:16:10 +01:00
parent 16c7fe1d4f
commit 41054cfb05
52 changed files with 165 additions and 21 deletions

View File

@@ -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

View File

@@ -10,7 +10,7 @@
namespace Smarty\Compile;
use Smarty\Compile\Tag\Base;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Block Plugin Class

View File

@@ -1,6 +1,6 @@
<?php
namespace Smarty\Compile\Tag;
namespace Smarty\Compile;
/**
* This class does extend all internal compile plugins
@@ -8,7 +8,7 @@ namespace Smarty\Compile\Tag;
* @package Smarty
* @subpackage Compiler
*/
interface TagCompilerInterface {
interface CompilerInterface {
/**
* Compiles code for the tag

View File

@@ -0,0 +1,55 @@
<?php
namespace Smarty\Compile;
use Smarty\Compiler\Template;
class DefaultHandlerFunctionCallCompiler extends Base {
/**
* Attribute definition: Overwrites base class.
*
* @var array
* @see BasePlugin
*/
public $optional_attributes = ['_any'];
/**
* Compiles code for the execution of a registered function
*
* @param array $args array with attributes from parser
* @param Template $compiler compiler object
* @param array $parameter array with compilation parameter
* @param string $tag name of tag
* @param string $function name of function
*
* @return string compiled code
* @throws \Smarty\CompilerException
* @throws \Smarty\Exception
*/
public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null) {
// check and get attributes
$_attr = $this->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 "<?php echo {$output};?>\n";
}
}

View File

@@ -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

View File

@@ -10,7 +10,7 @@
namespace Smarty\Compile;
use Smarty\Compile\Tag\Base;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Modifier Class

View File

@@ -10,7 +10,7 @@
namespace Smarty\Compile;
use Smarty\Compile\Tag\Base;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Object Function Class

View File

@@ -10,7 +10,7 @@
namespace Smarty\Compile;
use Smarty\Compile\Tag\Base;
use Smarty\Compile\Base;
use Smarty\Compiler\BaseCompiler;
/**

View File

@@ -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;

View File

@@ -2,6 +2,7 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
use Smarty\Smarty;
/**

View File

@@ -2,6 +2,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
class BCPluginWrapper extends Base {
private $callback;

View File

@@ -10,6 +10,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Break Class
*

View File

@@ -10,6 +10,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Function_Call Class
*

View File

@@ -2,6 +2,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Capture Class
*

View File

@@ -10,6 +10,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Captureclose Class
*

View File

@@ -10,6 +10,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Child Class
*

View File

@@ -10,6 +10,7 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
use Smarty\Smarty;
/**

View File

@@ -11,6 +11,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Debug Class
*

View File

@@ -2,6 +2,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile ElseIf Class
*

View File

@@ -2,6 +2,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Else Class
*

View File

@@ -10,6 +10,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Eval Class
*

View File

@@ -10,6 +10,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Forclose Class
*

View File

@@ -2,6 +2,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Forelse Class
*

View File

@@ -2,6 +2,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile For Class
*

View File

@@ -10,6 +10,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Foreachclose Class
*

View File

@@ -2,6 +2,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Foreachelse Class
*

View File

@@ -10,6 +10,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile ForeachSection Class
*

View File

@@ -10,6 +10,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Functionclose Class
*

View File

@@ -2,6 +2,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Function Class
*

View File

@@ -10,6 +10,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Ifclose Class
*

View File

@@ -2,6 +2,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile If Class
*

View File

@@ -10,6 +10,7 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
use Smarty\Compiler\Template;
use Smarty\Smarty;
use Smarty\Template\Compiled;

View File

@@ -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

View File

@@ -10,6 +10,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Ldelim Class
*

View File

@@ -10,6 +10,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Make_Nocache Class
*

View File

@@ -2,6 +2,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Nocache Class
*

View File

@@ -10,6 +10,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Nocacheclose Class
*

View File

@@ -10,6 +10,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Sectionclose Class
*

View File

@@ -2,6 +2,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Sectionelse Class
*

View File

@@ -2,6 +2,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Setfilter Class
*

View File

@@ -10,6 +10,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Setfilterclose Class
*

View File

@@ -10,6 +10,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile Whileclose Class
*

View File

@@ -2,6 +2,8 @@
namespace Smarty\Compile\Tag;
use Smarty\Compile\Base;
/**
* Smarty Internal Plugin Compile While Class
*

View File

@@ -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);
}

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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();

View File

@@ -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;

View File

@@ -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

View File

@@ -1,7 +1,7 @@
<?php
// compiler.test.php
use Smarty\Compile\Tag\Base;
use Smarty\Compile\Base;
class smarty_compiler_test extends Base
{

View File

@@ -1,7 +1,7 @@
<?php
// compiler.testclose.php
use Smarty\Compile\Tag\Base;
use Smarty\Compile\Base;
class smarty_compiler_testclose extends Base
{

View File

@@ -6,7 +6,7 @@
* @subpackage PHPunitPlugin
*/
use Smarty\Compile\Tag\Base;
use Smarty\Compile\Base;
/**
* Smarty {getparams}