mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
- improvement runtime checks if registered block plugins are callabel
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
02.01.2016
|
02.01.2016
|
||||||
- update scope handling
|
- update scope handling
|
||||||
- optimize block plugin compiler
|
- optimize block plugin compiler
|
||||||
|
- improvement runtime checks if registered block plugins are callabel
|
||||||
|
|
||||||
01.01.2016
|
01.01.2016
|
||||||
- remove Smarty::$resource_cache_mode property
|
- remove Smarty::$resource_cache_mode property
|
||||||
|
@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
|
|||||||
/**
|
/**
|
||||||
* smarty version
|
* smarty version
|
||||||
*/
|
*/
|
||||||
const SMARTY_VERSION = '3.1.30-dev/17';
|
const SMARTY_VERSION = '3.1.30-dev/18';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* define variable scopes
|
* define variable scopes
|
||||||
|
@@ -29,7 +29,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
|
|||||||
*
|
*
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $nesting = 0;
|
public $nesting = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles code for the execution of block plugin
|
* Compiles code for the execution of block plugin
|
||||||
@@ -53,15 +53,23 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
|
|||||||
$compiler->tag_nocache = true;
|
$compiler->tag_nocache = true;
|
||||||
}
|
}
|
||||||
unset($_attr[ 'nocache' ]);
|
unset($_attr[ 'nocache' ]);
|
||||||
list($callback, $_paramsArray) = $this->setup($compiler, $_attr, $tag, $function);
|
list($callback, $_paramsArray, $callable) = $this->setup($compiler, $_attr, $tag, $function);
|
||||||
$_params = 'array(' . implode(",", $_paramsArray) . ')';
|
$_params = 'array(' . implode(",", $_paramsArray) . ')';
|
||||||
|
|
||||||
|
// compile code
|
||||||
|
$output = "<?php ";
|
||||||
|
if (is_array($callback)) {
|
||||||
|
$output .= "\$_block_plugin{$this->nesting} = isset({$callback[0]}) ? {$callback[0]} : null;\n";
|
||||||
|
$callback = "\$_block_plugin{$this->nesting}{$callback[1]}";
|
||||||
|
}
|
||||||
|
if (isset($callable)) {
|
||||||
|
$output .= "if (!is_callable({$callable})) {\nthrow new SmartyException('block tag \'{$tag}\' not callable or registered');\n}\n";
|
||||||
|
}
|
||||||
|
$output .=
|
||||||
|
"\$_block_repeat{$this->nesting}=true;\necho {$callback}({$_params}, null, \$_smarty_tpl, \$_block_repeat{$this->nesting});\nwhile (\$_block_repeat{$this->nesting}) {\nob_start();\n?>";
|
||||||
$this->openTag($compiler, $tag, array($_params, $compiler->nocache, $callback));
|
$this->openTag($compiler, $tag, array($_params, $compiler->nocache, $callback));
|
||||||
// maybe nocache because of nocache variables or nocache plugin
|
// maybe nocache because of nocache variables or nocache plugin
|
||||||
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
|
||||||
// compile code
|
|
||||||
$output =
|
|
||||||
"<?php \$_block_repeat{$this->nesting}=true;\necho {$callback}({$_params}, null, \$_smarty_tpl, \$_block_repeat{$this->nesting});\nwhile (\$_block_repeat{$this->nesting}) {\nob_start();\n?>";
|
|
||||||
} else {
|
} else {
|
||||||
// must endblock be nocache?
|
// must endblock be nocache?
|
||||||
if ($compiler->nocache) {
|
if ($compiler->nocache) {
|
||||||
@@ -111,6 +119,6 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
|
|||||||
$_paramsArray[] = "'$_key'=>$_value";
|
$_paramsArray[] = "'$_key'=>$_value";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return array($function, $_paramsArray);
|
return array($function, $_paramsArray, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,7 +36,7 @@ class Smarty_Internal_Compile_Private_Object_Block_Function extends Smarty_Inter
|
|||||||
$_paramsArray[] = "'$_key'=>$_value";
|
$_paramsArray[] = "'$_key'=>$_value";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$callback = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}";
|
$callback = array("\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]", "->{$method}");
|
||||||
return array($callback, $_paramsArray);
|
return array($callback, $_paramsArray, "array(\$_block_plugin{$this->nesting}, '{$method}')");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,18 +30,30 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
|
|||||||
{
|
{
|
||||||
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag])) {
|
if (isset($compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag])) {
|
||||||
$tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag];
|
$tag_info = $compiler->smarty->registered_plugins[Smarty::PLUGIN_BLOCK][$tag];
|
||||||
} else {
|
|
||||||
$tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$tag];
|
|
||||||
}
|
|
||||||
$compiler->tag_nocache = !$tag_info[ 1 ] | $compiler->tag_nocache;
|
|
||||||
$callback = $tag_info[ 0 ];
|
$callback = $tag_info[ 0 ];
|
||||||
if (is_array($callback)) {
|
if (is_array($callback)) {
|
||||||
if (is_object($callback[ 0 ])) {
|
if (is_object($callback[ 0 ])) {
|
||||||
$callback = "\$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$callback[1]}";
|
$callable = "array(\$_block_plugin{$this->nesting}, '{$callback[1]}')";
|
||||||
|
$callback = array("\$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]", "->{$callback[1]}");
|
||||||
} else {
|
} else {
|
||||||
$callback = "{$callback[0]}::{$callback[1]}";
|
$callable = "array(\$_block_plugin{$this->nesting}, '{$callback[1]}')";
|
||||||
|
$callback = array("\$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]", "::{$callback[1]}");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$callable = "\$_block_plugin{$this->nesting}";
|
||||||
|
$callback = array("\$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0]", '');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$tag];
|
||||||
|
$callback = $tag_info[ 0 ];
|
||||||
|
if (is_array($callback)) {
|
||||||
|
$callable = "array('{$callback[0]}', '{$callback[1]}')";
|
||||||
|
$callback = "{$callback[1]}::{$callback[1]}";
|
||||||
|
} else {
|
||||||
|
$callable = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$compiler->tag_nocache = !$tag_info[ 1 ] | $compiler->tag_nocache;
|
||||||
$_paramsArray = array();
|
$_paramsArray = array();
|
||||||
foreach ($_attr as $_key => $_value) {
|
foreach ($_attr as $_key => $_value) {
|
||||||
if (is_int($_key)) {
|
if (is_int($_key)) {
|
||||||
@@ -53,6 +65,6 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
|
|||||||
$_paramsArray[] = "'$_key'=>$_value";
|
$_paramsArray[] = "'$_key'=>$_value";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return array($callback, $_paramsArray);
|
return array($callback, $_paramsArray, $callable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user