- 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
- update scope handling
- optimize block plugin compiler
- improvement runtime checks if registered block plugins are callabel
01.01.2016
- remove Smarty::$resource_cache_mode property

View File

@@ -121,7 +121,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
const SMARTY_VERSION = '3.1.30-dev/17';
const SMARTY_VERSION = '3.1.30-dev/18';
/**
* define variable scopes

View File

@@ -29,7 +29,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
*
* @var int
*/
private $nesting = 0;
public $nesting = 0;
/**
* 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;
}
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) . ')';
// 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));
// maybe nocache because of nocache variables or nocache plugin
$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 {
// must endblock be nocache?
if ($compiler->nocache) {
@@ -111,6 +119,6 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
$_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";
}
}
$callback = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}";
return array($callback, $_paramsArray);
$callback = array("\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]", "->{$method}");
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])) {
$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 ];
if (is_array($callback)) {
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 {
$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();
foreach ($_attr as $_key => $_value) {
if (is_int($_key)) {
@@ -53,6 +65,6 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
$_paramsArray[] = "'$_key'=>$_value";
}
}
return array($callback, $_paramsArray);
return array($callback, $_paramsArray, $callable);
}
}