- bugfix {$smarty.section.customer.loop} did throw compiler error https://github.com/smarty-php/smarty/issues/161

update of yesterdays fix
This commit is contained in:
uwetews
2016-01-26 21:25:29 +01:00
parent 8a0c783b71
commit 0b31052418
3 changed files with 158 additions and 159 deletions

View File

@@ -1,6 +1,8 @@
 ===== 3.1.30-dev ===== (xx.xx.xx)  ===== 3.1.30-dev ===== (xx.xx.xx)
27.01.2016 27.01.2016
- revert bugfix compiling {section} did create warning - revert bugfix compiling {section} did create warning
- bugfix {$smarty.section.customer.loop} did throw compiler error https://github.com/smarty-php/smarty/issues/161
update of yesterdays fix
26.01.2016 26.01.2016
- improvement observe Smarty::$_CHARSET in debugging console https://github.com/smarty-php/smarty/issues/169 - improvement observe Smarty::$_CHARSET in debugging console https://github.com/smarty-php/smarty/issues/169

View File

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

View File

@@ -16,14 +16,6 @@
*/ */
class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_ForeachSection class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_ForeachSection
{ {
/**
* Valid properties of $smarty.section.name.xxx variable
*
* @var array
*/
public $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'rownum', 'index_prev',
'index_next', 'loop');
/** /**
* Attribute definition: Overwrites base class. * Attribute definition: Overwrites base class.
* *
@@ -62,6 +54,14 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
*/ */
public $tagName = 'section'; public $tagName = 'section';
/**
* Valid properties of $smarty.section.name.xxx variable
*
* @var array
*/
public $nameProperties = array('first', 'last', 'index', 'iteration', 'show', 'total', 'rownum',
'index_prev', 'index_next', 'loop');
/** /**
* {section} tag has no item properties * {section} tag has no item properties
* *
@@ -80,13 +80,12 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
* Compiles code for the {section} tag * Compiles code for the {section} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompiler $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param null $parameter
* *
* @return string compiled code * @return string compiled code
* @throws \SmartyCompilerException * @throws \SmartyCompilerException
*/ */
public function compile($args, Smarty_Internal_TemplateCompiler $compiler, $parameter = null) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$compiler->loopNesting++; $compiler->loopNesting++;
// check and get attributes // check and get attributes
@@ -104,8 +103,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
// maybe nocache because of nocache variables // maybe nocache because of nocache variables
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache; $compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
$initLocal = $initLocal = array('saved' => "isset(\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']) ? \$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}'] : false",);
array('saved' => "isset(\$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}']) ? \$_smarty_tpl->tpl_vars['__smarty_section_{$attributes['name']}'] : false",);
$initNamedProperty = array(); $initNamedProperty = array();
$initFor = array(); $initFor = array();
$incFor = array(); $incFor = array();
@@ -121,8 +119,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$namedAttr = $this->matchResults['named']; $namedAttr = $this->matchResults['named'];
} }
$namedAttr['index'] = true; $namedAttr['index'] = true;
$v = $t = null; $output = "<?php\n";
$output = '';
foreach ($_attr as $attr_name => $attr_value) { foreach ($_attr as $attr_name => $attr_value) {
switch ($attr_name) { switch ($attr_name) {
case 'loop': case 'loop':
@@ -217,8 +214,8 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
} }
if (!isset($propValue['start'])) { if (!isset($propValue['start'])) {
$start_code = $start_code = array(1 => "{$propValue['step']} > 0 ? ", 2 => '0', 3 => ' : ', 4 => $propValue['loop'],
array(1 => "{$propValue['step']} > 0 ? ", 2 => '0', 3 => ' : ', 4 => $propValue[ 'loop' ], 5 => ' - 1'); 5 => ' - 1');
if ($propType['loop'] == 0) { if ($propType['loop'] == 0) {
$start_code[5] = ''; $start_code[5] = '';
$start_code[4] = $propValue['loop'] - 1; $start_code[4] = $propValue['loop'] - 1;
@@ -236,10 +233,10 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
} }
$propValue['start'] = join('', $start_code); $propValue['start'] = join('', $start_code);
} else { } else {
$start_code = $start_code = array(1 => "{$propValue['start']} < 0 ? ", 2 => 'max(', 3 => "{$propValue['step']} > 0 ? ",
array(1 => "{$propValue['start']} < 0 ? ", 2 => 'max(', 3 => "{$propValue['step']} > 0 ? ", 4 => '0', 4 => '0', 5 => ' : ', 6 => '-1', 7 => ', ',
5 => ' : ', 6 => '-1', 7 => ', ', 8 => "{$propValue['start']} + {$propValue['loop']}", 10 => ')', 8 => "{$propValue['start']} + {$propValue['loop']}", 10 => ')', 11 => ' : ',
11 => ' : ', 12 => 'min(', 13 => $propValue[ 'start' ], 14 => ', ', 12 => 'min(', 13 => $propValue['start'], 14 => ', ',
15 => "{$propValue['step']} > 0 ? ", 16 => $propValue['loop'], 17 => ' : ', 15 => "{$propValue['step']} > 0 ? ", 16 => $propValue['loop'], 17 => ' : ',
18 => $propType['loop'] == 0 ? $propValue['loop'] - 1 : "{$propValue['loop']} - 1", 18 => $propType['loop'] == 0 ? $propValue['loop'] - 1 : "{$propValue['loop']} - 1",
19 => ')'); 19 => ')');
@@ -262,17 +259,16 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$start_code[$i] = ''; $start_code[$i] = '';
} }
if ($propType['start'] == 0) { if ($propType['start'] == 0) {
$start_code = array(max($propValue[ 'step' ] > 0 ? 0 : - 1, $start_code = array(max($propValue['step'] > 0 ? 0 : - 1, $propValue['start'] +
$propValue[ 'start' ] + $propValue[ 'loop' ])); $propValue['loop']));
} }
} else { } else {
for ($i = 1; $i <= 11; $i ++) { for ($i = 1; $i <= 11; $i ++) {
$start_code[$i] = ''; $start_code[$i] = '';
} }
if ($propType['start'] == 0) { if ($propType['start'] == 0) {
$start_code = $start_code = array(min($propValue['step'] > 0 ? $propValue['loop'] : $propValue['loop'] -
array(min($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] : $propValue[ 'loop' ] - 1, 1, $propValue['start']));
$propValue[ 'start' ]));
} }
} }
} }
@@ -289,12 +285,11 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
$propValue['total'] = $propValue['loop']; $propValue['total'] = $propValue['loop'];
$propType['total'] = $propType['loop']; $propType['total'] = $propType['loop'];
} else { } else {
$propType[ 'total' ] = $propType['total'] = $propType['start'] + $propType['loop'] + $propType['step'] + $propType['max'];
$propType[ 'start' ] + $propType[ 'loop' ] + $propType[ 'step' ] + $propType[ 'max' ];
if ($propType['total'] == 0) { if ($propType['total'] == 0) {
$propValue[ 'total' ] = $propValue['total'] = min(ceil(($propValue['step'] > 0 ? $propValue['loop'] -
min(ceil(($propValue[ 'step' ] > 0 ? $propValue[ 'loop' ] - $propValue[ 'start' ] : $propValue['start'] : (int) $propValue['start'] + 1) /
(int) $propValue[ 'start' ] + 1) / abs($propValue[ 'step' ])), $propValue[ 'max' ]); abs($propValue['step'])), $propValue['max']);
} else { } else {
$total_code = array(1 => 'min(', 2 => 'ceil(', 3 => '(', 4 => "{$propValue['step']} > 0 ? ", $total_code = array(1 => 'min(', 2 => 'ceil(', 3 => '(', 4 => "{$propValue['step']} > 0 ? ",
5 => $propValue['loop'], 6 => ' - ', 7 => $propValue['start'], 8 => ' : ', 5 => $propValue['loop'], 6 => ' - ', 7 => $propValue['start'], 8 => ' : ',
@@ -329,7 +324,7 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
} }
} }
if (isset($namedAttr[ 'total' ])) { if (isset($namedAttr[ 'loop' ])) {
$initNamedProperty[ 'loop' ] = "'loop' => {$propValue['total']}"; $initNamedProperty[ 'loop' ] = "'loop' => {$propValue['total']}";
} }
if (isset($namedAttr['total'])) { if (isset($namedAttr['total'])) {
@@ -385,6 +380,8 @@ class Smarty_Internal_Compile_Section extends Smarty_Internal_Compile_Private_Fo
if (isset($namedAttr['last'])) { if (isset($namedAttr['last'])) {
$output .= "{$sectionVar}->value['last'] = ({$propValue['iteration']} == {$propValue['total']});\n"; $output .= "{$sectionVar}->value['last'] = ({$propValue['iteration']} == {$propValue['total']});\n";
} }
$output .= "?>";
return $output; return $output;
} }
} }
@@ -401,12 +398,11 @@ class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase
* Compiles code for the {sectionelse} tag * Compiles code for the {sectionelse} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompiler $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param null $parameter
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, Smarty_Internal_TemplateCompiler $compiler, $parameter = null) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
// check and get attributes // check and get attributes
$_attr = $this->getAttributes($compiler, $args); $_attr = $this->getAttributes($compiler, $args);
@@ -414,7 +410,7 @@ class Smarty_Internal_Compile_Sectionelse extends Smarty_Internal_CompileBase
list($openTag, $nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section')); list($openTag, $nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section'));
$this->openTag($compiler, 'sectionelse', array('sectionelse', $nocache, $local, $sectionVar)); $this->openTag($compiler, 'sectionelse', array('sectionelse', $nocache, $local, $sectionVar));
return "}\n} else {\n"; return "<?php }} else {\n ?>";
} }
} }
@@ -430,12 +426,11 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
* Compiles code for the {/section} tag * Compiles code for the {/section} tag
* *
* @param array $args array with attributes from parser * @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompiler $compiler compiler object * @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param null $parameter
* *
* @return string compiled code * @return string compiled code
*/ */
public function compile($args, Smarty_Internal_TemplateCompiler $compiler, $parameter = null) public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler)
{ {
$compiler->loopNesting--; $compiler->loopNesting--;
// must endblock be nocache? // must endblock be nocache?
@@ -443,10 +438,10 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
$compiler->tag_nocache = true; $compiler->tag_nocache = true;
} }
list($openTag, $compiler->nocache, $local, $sectionVar) = list($openTag, $compiler->nocache, $local, $sectionVar) = $this->closeTag($compiler, array('section',
$this->closeTag($compiler, array('section', 'sectionelse')); 'sectionelse'));
$output = ''; $output = "<?php\n";
if ($openTag == 'sectionelse') { if ($openTag == 'sectionelse') {
$output .= "}\n"; $output .= "}\n";
} else { } else {
@@ -455,6 +450,8 @@ class Smarty_Internal_Compile_Sectionclose extends Smarty_Internal_CompileBase
$output .= "if ({$local}saved) {\n"; $output .= "if ({$local}saved) {\n";
$output .= "{$sectionVar} = {$local}saved;\n"; $output .= "{$sectionVar} = {$local}saved;\n";
$output .= "}\n"; $output .= "}\n";
$output .= "?>";
return $output; return $output;
} }
} }