cvs: smarty / NEWS /libs Smarty.class.php Smarty_Compiler.class.php /libs/core core.process_compiled_include.php
"Messju Mohr" <[email protected]>
| Newsgroups | gmane.comp.php.cvs.smarty |
|---|---|
| Message-ID | <cvsmessju1060169759@cvsserver> |
messju Wed Aug 6 07:35:59 2003 EDT
Modified files:
/smarty NEWS
/smarty/libs Smarty.class.php Smarty_Compiler.class.php
/smarty/libs/core core.process_compiled_include.php
Log:
added optional parameter $cache_attrs to register_function() and
register_block(). $cache_attrs is an array containing attribute- names
that should be cached on calls to functions that have $cacheable set
to false.
--
Smarty CVS Mailing List (http://cvs.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
messju-20030806073559.txt
(text/plain, 8.7 KB)
Index: smarty/NEWS
diff -u smarty/NEWS:1.385 smarty/NEWS:1.386
--- smarty/NEWS:1.385 Thu Jul 31 09:51:28 2003
+++ smarty/NEWS Wed Aug 6 07:35:58 2003
@@ -1,3 +1,7 @@
+ - added optional parameter $cache_attrs to register_function() and
+ register_block(). $cache_attrs is an array containing attribute-
+ names that should be cached on calls to functions that have
+ $cacheable set to false. (messju)
- enabled registration of class-methods as callbacks for the register_*-
functions (use: array('classname', 'method_name')) as callback) (messju)
- added filepath caching (Monte)
@@ -46,7 +50,7 @@
- all in-code doc comments converted to phpDocumentor format (Greg)
- moved strip from smarty core to plugin (Monte)
- moved config_load from smarty core to plugin (Monte)
- - added &$repeat-paramter to block-functions (messju)
+ - added &$repeat-parameter to block-functions (messju)
- enabled hex-constants in function.math.php (messju)
- enabled hex-constants (0x...) as function-attributes, inside if-statements
and as modifier-parameters (messju)
Index: smarty/libs/Smarty.class.php
diff -u smarty/libs/Smarty.class.php:1.430 smarty/libs/Smarty.class.php:1.431
--- smarty/libs/Smarty.class.php:1.430 Wed Aug 6 07:33:09 2003
+++ smarty/libs/Smarty.class.php Wed Aug 6 07:35:58 2003
@@ -1,4 +1,5 @@
<?php
+
/**
* Project: Smarty: the PHP compiling template engine
* File: Smarty.class.php
@@ -42,7 +43,7 @@
* @version 2.5.0-cvs
*/
-/* $Id: Smarty.class.php,v 1.430 2003/08/06 11:33:09 messju Exp $ */
+/* $Id: Smarty.class.php,v 1.431 2003/08/06 11:35:58 messju Exp $ */
/**
* DIR_SEP isn't used anymore, but third party apps might
@@ -579,6 +580,14 @@
var $_cache_include = null;
/**
+ * indicate if the current code is used in a compiled
+ * include
+ *
+ * @var string
+ */
+ var $_cache_including = false;
+
+ /**
* cached file paths
*
* @var array
@@ -737,10 +746,11 @@
* @param string $function the name of the template function
* @param string $function_impl the name of the PHP function to register
*/
- function register_function($function, $function_impl, $cacheable=true)
+ function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null)
{
$this->_plugins['function'][$function] =
- array($function_impl, null, null, false, $cacheable);
+ array($function_impl, null, null, false, $cacheable, $cache_attrs);
+
}
/**
@@ -787,10 +797,10 @@
* @param string $block name of template block
* @param string $block_impl PHP function to register
*/
- function register_block($block, $block_impl, $cacheable=true)
+ function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null)
{
$this->_plugins['block'][$block] =
- array($block_impl, null, null, false, $cacheable);
+ array($block_impl, null, null, false, $cacheable, $cache_attrs);
}
/**
Index: smarty/libs/Smarty_Compiler.class.php
diff -u smarty/libs/Smarty_Compiler.class.php:1.270 smarty/libs/Smarty_Compiler.class.php:1.271
--- smarty/libs/Smarty_Compiler.class.php:1.270 Wed Aug 6 04:16:29 2003
+++ smarty/libs/Smarty_Compiler.class.php Wed Aug 6 07:35:58 2003
@@ -39,7 +39,7 @@
* @package Smarty
*/
-/* $Id: Smarty_Compiler.class.php,v 1.270 2003/08/06 08:16:29 messju Exp $ */
+/* $Id: Smarty_Compiler.class.php,v 1.271 2003/08/06 11:35:58 messju Exp $ */
/**
* Template compiling class
@@ -82,6 +82,7 @@
var $_obj_call_regexp = null;
var $_cacheable_state = 0;
+ var $_cache_attrs_count = 0;
var $_nocache_count = 0;
var $_cache_serial = null;
var $_cache_include = null;
@@ -655,16 +656,10 @@
$this->_add_plugin('block', $tag_command);
if ($start_tag) {
- $arg_list = array();
- $attrs = $this->_parse_attrs($tag_args);
- foreach ($attrs as $arg_name => $arg_value) {
- if (is_bool($arg_value))
- $arg_value = $arg_value ? 'true' : 'false';
- $arg_list[] = "'$arg_name' => $arg_value";
- }
-
$output = '<?php ' . $this->_push_cacheable_state('block', $tag_command);
- $output .= "\$_params = \$this->_tag_stack[] = array('$tag_command', array(".implode(',', (array)$arg_list).')); ';
+ $attrs = $this->_parse_attrs($tag_args);
+ $arg_list = $this->_compile_arg_list('block', $tag_command, $attrs, $_cache_attrs='');
+ $output .= "$_cache_attrs\$_params = \$this->_tag_stack[] = array('$tag_command', array(".implode(',', $arg_list).')); ';
$output .= $this->_compile_plugin_call('block', $tag_command).'($_params[1], null, $this, $_block_repeat=true); unset($_params);';
$output .= 'while ($_block_repeat) { ob_start(); ?>';
} else {
@@ -693,26 +688,20 @@
{
$this->_add_plugin('function', $tag_command);
- $arg_list = array();
+ $_cacheable_state = $this->_push_cacheable_state('function', $tag_command);
$attrs = $this->_parse_attrs($tag_args);
+ $arg_list = $this->_compile_arg_list('function', $tag_command, $attrs, $_cache_attrs='');
- foreach ($attrs as $arg_name => $arg_value) {
- if (is_bool($arg_value))
- $arg_value = $arg_value ? 'true' : 'false';
- if (is_null($arg_value))
- $arg_value = 'null';
- $arg_list[] = "'$arg_name' => $arg_value";
- }
- $_return = $this->_compile_plugin_call('function', $tag_command).'(array('.implode(',', (array)$arg_list)."), \$this)";
+ $_return = $_cache_attrs . $this->_compile_plugin_call('function', $tag_command).'(array('.implode(',', $arg_list)."), \$this)";
if($tag_modifier != '') {
$this->_parse_modifiers($_return, $tag_modifier);
}
-
+
if($_return != '') {
- $_return = '<?php ' . $this->_push_cacheable_state('function', $tag_command)
- . 'echo ' . $_return . ';' . $this->_pop_cacheable_state('function', $tag_command) . "?>\n";
+ $_return = '<?php ' . $_cacheable_state . 'echo ' . $_return . ';'
+ . $this->_pop_cacheable_state('function', $tag_command) . "?>\n";
}
-
+
return $_return;
}
@@ -1292,6 +1281,39 @@
return '<?php if ('.implode(' ', $tokens).'): ?>';
}
+
+ function _compile_arg_list($type, $name, $attrs, &$cache_code) {
+ $arg_list = array();
+
+ if (isset($type) && isset($name)
+ && isset($this->_plugins[$type])
+ && isset($this->_plugins[$type][$name])
+ && empty($this->_plugins[$type][$name][4])
+ && is_array($this->_plugins[$type][$name][5])
+ ) {
+ /* we have a list of parameters that should be cached */
+ $_cache_attrs = $this->_plugins[$type][$name][5];
+ $_count = $this->_cache_attrs_count++;
+ $cache_code = "\$_cache_attrs =& \$this->_cache_info['cache_attrs']['$this->_cache_serial'][$_count];";
+
+ } else {
+ /* no parameters are cached */
+ $_cache_attrs = null;
+ }
+
+ foreach ($attrs as $arg_name => $arg_value) {
+ if (is_bool($arg_value))
+ $arg_value = $arg_value ? 'true' : 'false';
+ if (is_null($arg_value))
+ $arg_value = 'null';
+ if ($_cache_attrs && in_array($arg_name, $_cache_attrs)) {
+ $arg_list[] = "'$arg_name' => (\$this->_cache_including) ? \$_cache_attrs['$arg_name'] : (\$_cache_attrs['$arg_name']=$arg_value)";
+ } else {
+ $arg_list[] = "'$arg_name' => $arg_value";
+ }
+ }
+ return $arg_list;
+ }
/**
* Parse is expression
Index: smarty/libs/core/core.process_compiled_include.php
diff -u smarty/libs/core/core.process_compiled_include.php:1.3 smarty/libs/core/core.process_compiled_include.php:1.4
--- smarty/libs/core/core.process_compiled_include.php:1.3 Thu Jul 17 15:25:22 2003
+++ smarty/libs/core/core.process_compiled_include.php Wed Aug 6 07:35:59 2003
@@ -16,12 +16,16 @@
function smarty_core_process_compiled_include($params, &$smarty)
{
+ $_cache_including = $smarty->_cache_including;
+ $smarty->_cache_including = true;
+
$_return = $params['results'];
foreach ($smarty->_cache_serials as $_include_file_path=>$_cache_serial) {
$_return = preg_replace_callback('!(\{nocache\:('.$_cache_serial.')#(\d+)\})!s',
array(&$smarty, '_process_compiled_include_callback'),
$_return);
}
+ $smarty->_cache_including = $_cache_including;
return $_return;
}