mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-03 09:54:27 +02:00
Fixed DefaultPluginHandlerTest for function plugins (blocks still break)
This commit is contained in:
@@ -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
|
@@ -10,7 +10,7 @@
|
||||
|
||||
namespace Smarty\Compile;
|
||||
|
||||
use Smarty\Compile\Tag\Base;
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Block Plugin Class
|
||||
|
@@ -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
|
55
src/Compile/DefaultHandlerFunctionCallCompiler.php
Normal file
55
src/Compile/DefaultHandlerFunctionCallCompiler.php
Normal 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";
|
||||
}
|
||||
}
|
@@ -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
|
||||
|
@@ -10,7 +10,7 @@
|
||||
|
||||
namespace Smarty\Compile;
|
||||
|
||||
use Smarty\Compile\Tag\Base;
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Modifier Class
|
||||
|
@@ -10,7 +10,7 @@
|
||||
|
||||
namespace Smarty\Compile;
|
||||
|
||||
use Smarty\Compile\Tag\Base;
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Object Function Class
|
||||
|
@@ -10,7 +10,7 @@
|
||||
|
||||
namespace Smarty\Compile;
|
||||
|
||||
use Smarty\Compile\Tag\Base;
|
||||
use Smarty\Compile\Base;
|
||||
use Smarty\Compiler\BaseCompiler;
|
||||
|
||||
/**
|
||||
|
@@ -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;
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
use Smarty\Smarty;
|
||||
|
||||
/**
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
class BCPluginWrapper extends Base {
|
||||
|
||||
private $callback;
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Break Class
|
||||
*
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Function_Call Class
|
||||
*
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Capture Class
|
||||
*
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Captureclose Class
|
||||
*
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Child Class
|
||||
*
|
||||
|
@@ -10,6 +10,7 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
use Smarty\Smarty;
|
||||
|
||||
/**
|
||||
|
@@ -11,6 +11,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Debug Class
|
||||
*
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile ElseIf Class
|
||||
*
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Else Class
|
||||
*
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Eval Class
|
||||
*
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Forclose Class
|
||||
*
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Forelse Class
|
||||
*
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile For Class
|
||||
*
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Foreachclose Class
|
||||
*
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Foreachelse Class
|
||||
*
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile ForeachSection Class
|
||||
*
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Functionclose Class
|
||||
*
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Function Class
|
||||
*
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Ifclose Class
|
||||
*
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile If Class
|
||||
*
|
||||
|
@@ -10,6 +10,7 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
use Smarty\Compiler\Template;
|
||||
use Smarty\Smarty;
|
||||
use Smarty\Template\Compiled;
|
||||
|
@@ -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
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Ldelim Class
|
||||
*
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Make_Nocache Class
|
||||
*
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Nocache Class
|
||||
*
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Nocacheclose Class
|
||||
*
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Sectionclose Class
|
||||
*
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Sectionelse Class
|
||||
*
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Setfilter Class
|
||||
*
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Setfilterclose Class
|
||||
*
|
||||
|
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Whileclose Class
|
||||
*
|
||||
|
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace Smarty\Compile\Tag;
|
||||
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty Internal Plugin Compile While Class
|
||||
*
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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) {
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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();
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
// compiler.test.php
|
||||
use Smarty\Compile\Tag\Base;
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
class smarty_compiler_test extends Base
|
||||
{
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
// compiler.testclose.php
|
||||
use Smarty\Compile\Tag\Base;
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
class smarty_compiler_testclose extends Base
|
||||
{
|
||||
|
@@ -6,7 +6,7 @@
|
||||
* @subpackage PHPunitPlugin
|
||||
*/
|
||||
|
||||
use Smarty\Compile\Tag\Base;
|
||||
use Smarty\Compile\Base;
|
||||
|
||||
/**
|
||||
* Smarty {getparams}
|
||||
|
Reference in New Issue
Block a user