update of the $smarty->merge_compiled_includes option

This commit is contained in:
Uwe Tews
2014-11-11 00:03:08 +01:00
parent 460be5a5da
commit 9ecbb93ebb
2 changed files with 26 additions and 25 deletions

View File

@@ -52,13 +52,14 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
/** /**
* Compiles code for the {include} tag * Compiles code for the {include} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param object $compiler compiler object * @param Smarty_Internal_SmartyTemplateCompiler $compiler compiler object
* @param array $parameter array with compilation parameter * @param array $parameter array with compilation parameter
* *
* @throws SmartyCompilerException
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, $compiler, $parameter) public function compile($args, Smarty_Internal_SmartyTemplateCompiler $compiler, $parameter)
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
@@ -83,7 +84,6 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
} }
} }
$call_nocache = false;
// assume caching is off // assume caching is off
$_caching = Smarty::CACHING_OFF; $_caching = Smarty::CACHING_OFF;
@@ -91,6 +91,8 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
$call_nocache = $compiler->tag_nocache || $compiler->nocache;
// caching was on and {include} is not in nocache mode // caching was on and {include} is not in nocache mode
if ($compiler->template->caching && !$compiler->nocache && !$compiler->tag_nocache) { if ($compiler->template->caching && !$compiler->nocache && !$compiler->tag_nocache) {
$_caching = self::CACHING_NOCACHE_CODE; $_caching = self::CACHING_NOCACHE_CODE;
@@ -98,14 +100,17 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
// flag if included template code should be merged into caller // flag if included template code should be merged into caller
$merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) || $_attr['inline'] === true) && !$compiler->template->source->recompiled; $merge_compiled_includes = ($compiler->smarty->merge_compiled_includes || ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) || $_attr['inline'] === true) && !$compiler->template->source->recompiled;
if ($merge_compiled_includes && $_attr['inline'] !== true) {
// variable template name ? // variable template name ?
if ($compiler->has_variable_string || !((substr_count($include_file, '"') == 2 || substr_count($include_file, "'") == 2)) if ($compiler->has_variable_string || !((substr_count($include_file, '"') == 2 || substr_count($include_file, "'") == 2))
|| substr_count($include_file, '(') != 0 || substr_count($include_file, '$_smarty_tpl->') != 0 || substr_count($include_file, '(') != 0 || substr_count($include_file, '$_smarty_tpl->') != 0
) { ) {
$merge_compiled_includes = false; $merge_compiled_includes = false;
$call_nocache = true; if ($compiler->template->caching) {
if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) { // must use individual cache file
$_attr['caching'] = 1;
}
if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes && $_attr['inline'] !== true) {
$compiler->trigger_template_error(' variable template file names not allow within {block} tags'); $compiler->trigger_template_error(' variable template file names not allow within {block} tags');
} }
} }
@@ -115,14 +120,16 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
|| substr_count($_attr['compile_id'], '(') != 0 || substr_count($_attr['compile_id'], '$_smarty_tpl->') != 0 || substr_count($_attr['compile_id'], '(') != 0 || substr_count($_attr['compile_id'], '$_smarty_tpl->') != 0
) { ) {
$merge_compiled_includes = false; $merge_compiled_includes = false;
$_attr['caching'] = 1; if ($compiler->template->caching) {
$call_nocache = 1; // must use individual cache file
if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes) { $_attr['caching'] = 1;
}
if ($compiler->inheritance && $compiler->smarty->inheritance_merge_compiled_includes && $_attr['inline'] !== true) {
$compiler->trigger_template_error(' variable compile_id not allow within {block} tags'); $compiler->trigger_template_error(' variable compile_id not allow within {block} tags');
} }
} }
} }
}
/* /*
* if the {include} tag provides individual parameter for caching or compile_id * if the {include} tag provides individual parameter for caching or compile_id
@@ -156,8 +163,9 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$_compile_id = '$_smarty_tpl->compile_id'; $_compile_id = '$_smarty_tpl->compile_id';
} }
if ($compiler->template->caching && ($compiler->nocache || $compiler->tag_nocache)) { // if subtemplate will be called in nocache mode do not merge
//$merge_compiled_includes = false; if ($compiler->template->caching && $call_nocache) {
$merge_compiled_includes = false;
} }
$has_compiled_template = false; $has_compiled_template = false;
@@ -216,6 +224,7 @@ class Smarty_Internal_Compile_Include extends Smarty_Internal_CompileBase
$_vars_nc = ''; $_vars_nc = '';
if (!empty($_attr)) { if (!empty($_attr)) {
if ($_parent_scope == Smarty::SCOPE_LOCAL) { if ($_parent_scope == Smarty::SCOPE_LOCAL) {
$_pairs = array();
// create variables // create variables
foreach ($_attr as $key => $value) { foreach ($_attr as $key => $value) {
$_pairs[] = "'$key'=>$value"; $_pairs[] = "'$key'=>$value";

View File

@@ -179,14 +179,6 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
{ {
if (!$this->source->recompiled) { if (!$this->source->recompiled) {
$this->properties['file_dependency'] = array(); $this->properties['file_dependency'] = array();
if ($this->source->components) {
// for the extends resource the compiler will fill it
// uses real resource for file dependency
// $source = end($this->source->components);
// $this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $source->type);
} else {
$this->properties['file_dependency'][$this->source->uid] = array($this->source->filepath, $this->source->timestamp, $this->source->type);
}
} }
// compile locking // compile locking
if ($this->smarty->compile_locking && !$this->source->recompiled) { if ($this->smarty->compile_locking && !$this->source->recompiled) {
@@ -390,7 +382,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
{ {
if (isset($_smarty_tpl->properties['tpl_function']['param'][$name])) { if (isset($_smarty_tpl->properties['tpl_function']['param'][$name])) {
if (!$_smarty_tpl->caching || ($_smarty_tpl->caching && $nocache) || $_smarty_tpl->properties['type'] !== 'cache') { if (!$_smarty_tpl->caching || ($_smarty_tpl->caching && $nocache) || $_smarty_tpl->properties['type'] !== 'cache') {
$_smarty_tpl->properties['tpl_function']['to_cache'][$name] = true; //$_smarty_tpl->properties['tpl_function']['to_cache'][$name] = true;
$function = $_smarty_tpl->properties['tpl_function']['param'][$name]['call_name']; $function = $_smarty_tpl->properties['tpl_function']['param'][$name]['call_name'];
} else { } else {
if (isset($_smarty_tpl->properties['tpl_function']['param'][$name]['call_name_caching'])) { if (isset($_smarty_tpl->properties['tpl_function']['param'][$name]['call_name_caching'])) {
@@ -401,7 +393,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
} }
if (function_exists($function)) { if (function_exists($function)) {
$function ($_smarty_tpl, $params); $function ($_smarty_tpl, $params);
return; return;
} }
// try to load template function dynamically // try to load template function dynamically
if (Smarty_Internal_Function_Call_Handler::call($name, $_smarty_tpl, $function, $params, $nocache)) { if (Smarty_Internal_Function_Call_Handler::call($name, $_smarty_tpl, $function, $params, $nocache)) {
@@ -481,7 +473,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase
$output .= $plugins_string . $content; $output .= $plugins_string . $content;
$output .= "<?php \$_smarty_tpl->properties['type'] = \$_saved_type;?>\n"; $output .= "<?php \$_smarty_tpl->properties['type'] = \$_saved_type;?>\n";
if (!$this->source->recompiled) { if (!$this->source->recompiled) {
$output .= "<?php }} ?>\n"; $output .= "<?php }\n}\n?>";
} }
return $output; return $output;
} }