- improvement runtime checks if registered block plugins are callabel

This commit is contained in:
uwetews
2016-01-02 17:58:58 +01:00
parent 418492b40b
commit dd0f4c7c36
5 changed files with 40 additions and 19 deletions

View File

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

View File

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

View File

@@ -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,16 +53,24 @@ 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 } else {
$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 {
// must endblock be nocache? // must endblock be nocache?
if ($compiler->nocache) { if ($compiler->nocache) {
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
@@ -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);
} }
} }

View File

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

View File

@@ -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];
$callback = $tag_info[ 0 ];
if (is_array($callback)) {
if (is_object($callback[ 0 ])) {
$callable = "array(\$_block_plugin{$this->nesting}, '{$callback[1]}')";
$callback = array("\$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]", "->{$callback[1]}");
} else {
$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 { } else {
$tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$tag]; $tag_info = $compiler->default_handler_plugins[Smarty::PLUGIN_BLOCK][$tag];
} $callback = $tag_info[ 0 ];
$compiler->tag_nocache = !$tag_info[ 1 ] | $compiler->tag_nocache; if (is_array($callback)) {
$callback = $tag_info[ 0 ]; $callable = "array('{$callback[0]}', '{$callback[1]}')";
if (is_array($callback)) { $callback = "{$callback[1]}::{$callback[1]}";
if (is_object($callback[ 0 ])) { } else {
$callback = "\$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$callback[1]}"; $callable = null;
} else {
$callback = "{$callback[0]}::{$callback[1]}";
} }
} }
$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);
} }
} }