mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-02 17:34:26 +02:00
move runPluginFromDefaultHandler to new Runtime class
This commit is contained in:
@@ -44,7 +44,7 @@ class DefaultHandlerFunctionCallCompiler extends Base {
|
||||
}
|
||||
$_params = 'array(' . implode(',', $_paramsArray) . ')';
|
||||
|
||||
$output = "\$_smarty_tpl->smarty->runPluginFromDefaultHandler(" . var_export($function, true) .
|
||||
$output = "\$_smarty_tpl->smarty->getRuntime('DefaultPluginHandler')->runPlugin(" . var_export($function, true) .
|
||||
",'function',$_params, \$_smarty_tpl)";
|
||||
|
||||
if (!empty($parameter['modifierlist'])) {
|
||||
|
48
src/Runtime/DefaultPluginHandlerRuntime.php
Normal file
48
src/Runtime/DefaultPluginHandlerRuntime.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Smarty\Runtime;
|
||||
|
||||
use Smarty\Exception;
|
||||
|
||||
class DefaultPluginHandlerRuntime {
|
||||
|
||||
/**
|
||||
* @var callable
|
||||
*/
|
||||
private $defaultPluginHandler;
|
||||
|
||||
public function __construct(?callable $defaultPluginHandler = null) {
|
||||
$this->defaultPluginHandler = $defaultPluginHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function runPlugin($tag, $plugin_type, $params, \Smarty\Template $template) {
|
||||
|
||||
if ($this->defaultPluginHandler === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$callback = null;
|
||||
|
||||
// these are not used here
|
||||
$script = null;
|
||||
$cacheable = null;
|
||||
|
||||
if (call_user_func_array(
|
||||
$this->defaultPluginHandler,
|
||||
[
|
||||
$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");
|
||||
}
|
||||
}
|
@@ -2075,6 +2075,10 @@ class Smarty extends \Smarty\TemplateBase
|
||||
return $this->runtimes[$type] = new \Smarty\Runtime\MakeNocacheRuntime();
|
||||
case 'TplFunction':
|
||||
return $this->runtimes[$type] = new \Smarty\Runtime\TplFunctionRuntime();
|
||||
case 'DefaultPluginHandler':
|
||||
return $this->runtimes[$type] = new \Smarty\Runtime\DefaultPluginHandlerRuntime(
|
||||
$this->getDefaultPluginHandlerFunc()
|
||||
);
|
||||
}
|
||||
|
||||
throw new \Smarty\Exception('Trying to load invalid runtime ' . $type);
|
||||
@@ -2103,31 +2107,6 @@ 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
|
||||
*
|
||||
|
Reference in New Issue
Block a user