mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-06 11:24:27 +02:00
- removed call_user_func_array calls for optimization of compiled code when using registered modifiers and plugins
- updated comments
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
01/07/2010
|
||||
- removed call_user_func_array calls for optimization of compiled code when using registered modifiers and plugins
|
||||
|
||||
25/06/2010
|
||||
- bugfix escaping " when block tags are used within doublequoted strings
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* Smarty plugin
|
||||
* @package Smarty
|
||||
* @subpackage plugins
|
||||
* @subpackage PluginsFunction
|
||||
*/
|
||||
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* Smarty plugin
|
||||
* @package Smarty
|
||||
* @subpackage plugins
|
||||
* @subpackage PluginsFunction
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@@ -2,8 +2,8 @@
|
||||
/**
|
||||
* Smarty plugin
|
||||
* @package Smarty
|
||||
* @subpackage plugins
|
||||
*/
|
||||
* @subpackage PluginsModifier
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
|
@@ -1,25 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Block Plugin
|
||||
*
|
||||
* Compiles code for the execution of block plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
* Smarty Internal Plugin Compile Block Plugin
|
||||
*
|
||||
* Compiles code for the execution of block plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Block Plugin Class
|
||||
*/
|
||||
* Smarty Internal Plugin Compile Block Plugin Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_CompileBase {
|
||||
/**
|
||||
* Compiles code for the execution of block plugin
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param string $tag name of block function
|
||||
* @param object $compiler compiler object
|
||||
* @return string compiled code
|
||||
*/
|
||||
* Compiles code for the execution of block plugin
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param string $tag name of block function
|
||||
* @param object $compiler compiler object
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $tag, $function)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
@@ -44,11 +44,7 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
|
||||
// maybe nocache because of nocache variables or nocache plugin
|
||||
$this->compiler->nocache = $this->compiler->nocache | $this->compiler->tag_nocache;
|
||||
// compile code
|
||||
if (is_array($function)) {
|
||||
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; call_user_func_array(array('{$function[0]}','{$function[1]}'),(array({$_params}, null, \$_smarty_tpl->smarty, &\$_block_repeat, \$_smarty_tpl));while (\$_block_repeat) { ob_start();?>";
|
||||
} else {
|
||||
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; {$function}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>";
|
||||
}
|
||||
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; {$function}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>";
|
||||
} else {
|
||||
// must endblock be nocache?
|
||||
if ($this->compiler->nocache) {
|
||||
@@ -59,13 +55,9 @@ class Smarty_Internal_Compile_Private_Block_Plugin extends Smarty_Internal_Compi
|
||||
// This tag does create output
|
||||
$this->compiler->has_output = true;
|
||||
// compile code
|
||||
if (is_array($function)) {
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false; echo call_user_func_array(array('{$function[0]}','{$function[1]}'),(array({$_params}, \$_block_content, \$_smarty_tpl->smarty, &\$_block_repeat, \$_smarty_tpl)); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
|
||||
} else {
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false; echo {$function}({$_params}, \$_block_content, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
|
||||
}
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false; echo {$function}({$_params}, \$_block_content, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
|
||||
}
|
||||
return $output."\n";
|
||||
return $output . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,25 +1,25 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Function Plugin
|
||||
*
|
||||
* Compiles code for the execution of function plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
* Smarty Internal Plugin Compile Function Plugin
|
||||
*
|
||||
* Compiles code for the execution of function plugin
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Function Plugin Class
|
||||
*/
|
||||
* Smarty Internal Plugin Compile Function Plugin Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_CompileBase {
|
||||
/**
|
||||
* Compiles code for the execution of function plugin
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param string $tag name of function
|
||||
* @param object $compiler compiler object
|
||||
* @return string compiled code
|
||||
*/
|
||||
* Compiles code for the execution of function plugin
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param string $tag name of function
|
||||
* @param object $compiler compiler object
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler, $tag, $function)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
@@ -41,11 +41,7 @@ class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_Co
|
||||
}
|
||||
$_params = 'array(' . implode(",", $_paramsArray) . ')';
|
||||
// compile code
|
||||
if (is_array($function)) {
|
||||
$output = "<?php echo call_user_func(array('{$function[0]}','{$function[1]}'),{$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n";
|
||||
} else {
|
||||
$output = "<?php echo {$function}({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n";
|
||||
}
|
||||
$output = "<?php echo {$function}({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n";
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
@@ -1,24 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Modifier
|
||||
*
|
||||
* Compiles code for modifier execution
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
* Smarty Internal Plugin Compile Modifier
|
||||
*
|
||||
* Compiles code for modifier execution
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
/**
|
||||
* Smarty Internal Plugin Compile Modifier Class
|
||||
*/
|
||||
* Smarty Internal Plugin Compile Modifier Class
|
||||
*/
|
||||
class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBase {
|
||||
/**
|
||||
* Compiles code for modifier execution
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @return string compiled code
|
||||
*/
|
||||
* Compiles code for modifier execution
|
||||
*
|
||||
* @param array $args array with attributes from parser
|
||||
* @param object $compiler compiler object
|
||||
* @return string compiled code
|
||||
*/
|
||||
public function compile($args, $compiler)
|
||||
{
|
||||
$this->compiler = $compiler;
|
||||
@@ -30,19 +30,17 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
if (isset($compiler->smarty->registered_plugins['modifier'][$_attr['modifier']])) {
|
||||
$function = $compiler->smarty->registered_plugins['modifier'][$_attr['modifier']][0];
|
||||
if (!is_array($function)) {
|
||||
$output = "{$function}({$_attr['params']})";
|
||||
} else if (is_object($function[0])) {
|
||||
$output = 'call_user_func_array($_smarty_tpl->smarty->registered_plugins[\'modifier\'][\'' . $_attr['modifier'] . '\'][0],array(' . $_attr['params'] . '))';
|
||||
$output = "{$function}({$_attr['params']})";
|
||||
} else {
|
||||
$output = 'call_user_func_array(array(\'' . $function[0] . '\',\'' . $function[1] . '\'),array(' . $_attr['params'] . '))';
|
||||
if (is_object($function[0])) {
|
||||
$output = '$_smarty_tpl->smarty->registered_plugins[\'modifier\'][\'' . $_attr['modifier'] . '\'][0][0]->' . $function[1] . '(' . $_attr['params'] . ')';
|
||||
} else {
|
||||
$output = $function[0] . '::' . $function[1] . '(' . $_attr['params'] . ')';
|
||||
}
|
||||
}
|
||||
// check for plugin modifier
|
||||
// check for plugin modifier
|
||||
} else if ($function = $this->compiler->getPlugin($_attr['modifier'], 'modifier')) {
|
||||
if (!is_array($function)) {
|
||||
$output = "{$function}({$_attr['params']})";
|
||||
} else {
|
||||
$output = 'call_user_func_array(array(\'' . $function[0] . '\',\'' . $function[1] . '\'),array(' . $_attr['params'] . '))';
|
||||
}
|
||||
$output = "{$function}({$_attr['params']})";
|
||||
// check if trusted PHP function
|
||||
} else if (is_callable($_attr['modifier'])) {
|
||||
// check if modifier allowed
|
||||
@@ -56,4 +54,4 @@ class Smarty_Internal_Compile_Private_Modifier extends Smarty_Internal_CompileBa
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
@@ -48,9 +48,9 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
|
||||
if (!is_array($function)) {
|
||||
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; {$function}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>";
|
||||
} else if (is_object($function[0])) {
|
||||
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; call_user_func_array(\$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0],array({$_params}, null, \$_smarty_tpl->smarty, &\$_block_repeat, \$_smarty_tpl));while (\$_block_repeat) { ob_start();?>";
|
||||
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; \$_smarty_tpl->smarty->registered_plugins['block']['{$tag}'][0][0]->{$function[1]}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>";
|
||||
} else {
|
||||
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; call_user_func_array(array('{$function[0]}','{$function[1]}'),array({$_params}, null, \$_smarty_tpl->smarty, &\$_block_repeat, \$_smarty_tpl));while (\$_block_repeat) { ob_start();?>";
|
||||
$output = "<?php \$_smarty_tpl->smarty->_tag_stack[] = array('{$tag}', {$_params}); \$_block_repeat=true; {$function[0]}::{$function[1]}({$_params}, null, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl);while (\$_block_repeat) { ob_start();?>";
|
||||
}
|
||||
} else {
|
||||
// must endblock be nocache?
|
||||
@@ -67,9 +67,9 @@ class Smarty_Internal_Compile_Private_Registered_Block extends Smarty_Internal_C
|
||||
if (!is_array($function)) {
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false; echo {$function}({$_params}, \$_block_content, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
|
||||
} else if (is_object($function[0])) {
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false; echo call_user_func_array(\$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0],array({$_params}, \$_block_content, \$_smarty_tpl->smarty, &\$_block_repeat, \$_smarty_tpl)); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false; echo \$_smarty_tpl->smarty->registered_plugins['block']['{$base_tag}'][0][0]->{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
|
||||
} else {
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false; echo call_user_func_array(array('{$function[0]}','{$function[1]}'),array({$_params}, \$_block_content, \$_smarty_tpl->smarty, &\$_block_repeat, \$_smarty_tpl)); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
|
||||
$output = "<?php \$_block_content = ob_get_clean(); \$_block_repeat=false; echo {$function[0]}::{$function[1]}({$_params}, \$_block_content, \$_smarty_tpl->smarty, \$_block_repeat, \$_smarty_tpl); } array_pop(\$_smarty_tpl->smarty->_tag_stack);?>";
|
||||
}
|
||||
}
|
||||
return $output."\n";
|
||||
|
@@ -42,15 +42,14 @@ class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Interna
|
||||
}
|
||||
}
|
||||
$_params = 'array(' . implode(",", $_paramsArray) . ')';
|
||||
// compile code
|
||||
$function = $compiler->smarty->registered_plugins['function'][$tag][0];
|
||||
// compile code
|
||||
if (!is_array($function)) {
|
||||
$output = "<?php echo {$function}({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n";
|
||||
} else if (is_object($function[0])) {
|
||||
$output = "<?php echo call_user_func(\$_smarty_tpl->smarty->registered_plugins['function']['{$tag}'][0],{$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n";
|
||||
$output = "<?php echo \$_smarty_tpl->smarty->registered_plugins['function']['{$tag}'][0][0]->{$function[1]}({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n";
|
||||
} else {
|
||||
$output = "<?php echo call_user_func(array('{$function[0]}','{$function[1]}'),{$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n";
|
||||
$output = "<?php echo {$function[0]}::{$function[1]}({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n";
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
@@ -1,4 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* Smarty Internal Plugin Templateparser Parsetrees
|
||||
*
|
||||
* These are classes to build parsetrees in the template parser
|
||||
*
|
||||
* @package Smarty
|
||||
* @subpackage Compiler
|
||||
* @author Thue Kristensen
|
||||
* @author Uwe Tews
|
||||
*/
|
||||
|
||||
abstract class _smarty_parsetree {
|
||||
abstract public function to_smarty_php();
|
||||
|
@@ -155,7 +155,14 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
if (!$this->smarty->registered_plugins[$type][$tag][1]) {
|
||||
$this->tag_nocache = true;
|
||||
}
|
||||
return call_user_func_array($this->smarty->registered_plugins[$type][$tag][0], array($args, $this));
|
||||
$function = $this->smarty->registered_plugins[$type][$tag][0];
|
||||
if (!is_array($function)) {
|
||||
return $function($args, $this);
|
||||
} else if (is_object($function[0])) {
|
||||
return $this->smarty->registered_plugins[$type][$tag][0][0]->$function[1]($args, $this);
|
||||
} else {
|
||||
return call_user_func_array($this->smarty->registered_plugins[$type][$tag][0], array($args, $this));
|
||||
}
|
||||
}
|
||||
// compile registered function or block function
|
||||
if ($type == 'function' || $type == 'block') {
|
||||
@@ -286,23 +293,6 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
}
|
||||
return $function;
|
||||
}
|
||||
/**
|
||||
* if (isset($this->template->required_plugins_call[$plugin_name][$type])) {
|
||||
* if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
|
||||
* if (isset($this->template->required_plugins['compiled'][$plugin_name])) {
|
||||
* $this->template->required_plugins['cache'][$plugin_name] = $this->template->required_plugins['compiled'][$plugin_name];
|
||||
* }
|
||||
* } else {
|
||||
* if (isset($this->template->required_plugins['cache'][$plugin_name])) {
|
||||
* $this->template->required_plugins['compiled'][$plugin_name] = $this->template->required_plugins['cache'][$plugin_name];
|
||||
* }
|
||||
* }
|
||||
* if ($type == 'modifier') {
|
||||
* $this->template->saved_modifier[$plugin_name] = true;
|
||||
* }
|
||||
* return $this->template->required_plugins_call[$plugin_name][$type];
|
||||
* }
|
||||
*/
|
||||
// loop through plugin dirs and find the plugin
|
||||
$function = 'smarty_' . $type . '_' . $plugin_name;
|
||||
$found = false;
|
||||
@@ -315,7 +305,6 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
}
|
||||
}
|
||||
if ($found) {
|
||||
// if (is_callable($plugin)) {
|
||||
if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
|
||||
$this->template->required_plugins['nocache'][$plugin_name][$type]['file'] = $file;
|
||||
$this->template->required_plugins['nocache'][$plugin_name][$type]['function'] = $function;
|
||||
@@ -323,16 +312,6 @@ class Smarty_Internal_TemplateCompilerBase {
|
||||
$this->template->required_plugins['compiled'][$plugin_name][$type]['file'] = $file;
|
||||
$this->template->required_plugins['compiled'][$plugin_name][$type]['function'] = $function;
|
||||
}
|
||||
/**
|
||||
* $this->template->required_plugins_call[$plugin_name][$type] = $plugin;
|
||||
* if ($this->template->caching && ($this->nocache || $this->tag_nocache)) {
|
||||
* $this->template->required_plugins['cache'][$plugin_name]['file'] = $file;
|
||||
* $this->template->required_plugins['cache'][$plugin_name]['type'] = $type;
|
||||
* } else {
|
||||
* $this->template->required_plugins['compiled'][$plugin_name]['file'] = $file;
|
||||
* $this->template->required_plugins['compiled'][$plugin_name]['type'] = $type;
|
||||
* }
|
||||
*/
|
||||
if ($type == 'modifier') {
|
||||
$this->template->saved_modifier[$plugin_name] = true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user