- bugfix compiling {section} did create warning

This commit is contained in:
uwetews
2016-01-26 02:57:21 +01:00
parent 8b0e0a3df6
commit b58e1cdc5a
2 changed files with 72 additions and 111 deletions

View File

@@ -1,6 +1,7 @@
 ===== 3.1.30-dev ===== (xx.xx.xx)  ===== 3.1.30-dev ===== (xx.xx.xx)
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
- bugfix compiling {section} did create warning
02.01.2016 02.01.2016
- update scope handling - update scope handling

View File

@@ -14,9 +14,42 @@
* @package Smarty * @package Smarty
* @subpackage Compiler * @subpackage Compiler
*/ */
class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_CompileBase abstract class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_CompileBase
{ {
/**
* Valid properties of $smarty.xxx variable
*
* @var array
*/
public $nameProperties = array();
/**
* Name of this tag
*
* @var string
*/
public $tagName = '';
/**
* {section} tag has no item properties
*
* @var array
*/
public $itemProperties = null;
/**
* {section} tag has always name attribute
*
* @var bool
*/
public $isNamed = true;
/**
* @var array
*/
public $matchResults = array();
/** /**
* Preg search pattern * Preg search pattern
* *
@@ -39,45 +72,37 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
private $startOffset = 0; private $startOffset = 0;
/** /**
* Name of this tag * Compiles code for the {$smarty.foreach.xxx} or {$smarty.section.xxx}tag
* *
* @var string * @param array $args array with attributes from parser
*/ * @param \Smarty_Internal_TemplateCompiler $compiler compiler object
public $tagName = ''; * @param array $parameter array with compilation parameter
/**
* Valid properties of $smarty.xxx variable
* *
* @var array * @return string compiled code
* @throws \SmartyCompilerException
*/ */
public $nameProperties = array(); public function compileSpecialVariable($args, Smarty_Internal_TemplateCompiler $compiler, $parameter = null)
{
/** $tag = strtolower(trim($parameter[ 0 ], '"\''));
* {section} tag has no item properties $name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : false;
* if (!$name) {
* @var array $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
*/ }
public $itemProperties = null; $property = isset($parameter[ 2 ]) ? strtolower($compiler->getId($parameter[ 2 ])) : false;
if (!$property || !in_array($property, $this->nameProperties)) {
/** $compiler->trigger_template_error("missing or illegal \$smarty.{$tag} property attribute", null, true);
* {section} tag has always name attribute }
* $tagVar = "'__smarty_{$tag}_{$name}'";
* @var bool return "(isset(\$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}'] : null)";
*/ }
public $isNamed = true;
/**
* @var array
*/
public $matchResults = array();
/** /**
* Scan sources for used tag attributes * Scan sources for used tag attributes
* *
* @param array $attributes * @param array $attributes
* @param \Smarty_Internal_TemplateCompilerBase $compiler * @param \Smarty_Internal_TemplateCompiler $compiler
*/ */
public function scanForProperties($attributes, Smarty_Internal_TemplateCompilerBase $compiler) public function scanForProperties($attributes, Smarty_Internal_TemplateCompiler $compiler)
{ {
$this->propertyPreg = '~('; $this->propertyPreg = '~(';
$this->startOffset = 0; $this->startOffset = 0;
@@ -95,10 +120,6 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
$this->propertyPreg .= ')\W~i'; $this->propertyPreg .= ')\W~i';
// Template source // Template source
$this->matchTemplateSource($compiler); $this->matchTemplateSource($compiler);
// Parent template source
$this->matchParentTemplateSource($compiler);
// {block} source
$this->matchBlockSource($compiler);
} }
/** /**
@@ -110,11 +131,11 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
public function buildPropertyPreg($named, $attributes) public function buildPropertyPreg($named, $attributes)
{ {
if ($named) { if ($named) {
$this->resultOffsets['named'] = $this->startOffset + 3; $this->resultOffsets[ 'named' ] = $this->startOffset + 3;
$this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.]("; $this->propertyPreg .= "([\$]smarty[.]{$this->tagName}[.]{$attributes['name']}[.](";
$properties = $this->nameProperties; $properties = $this->nameProperties;
} else { } else {
$this->resultOffsets['item'] = $this->startOffset + 3; $this->resultOffsets[ 'item' ] = $this->startOffset + 3;
$this->propertyPreg .= "([\$]{$attributes['item']}[@]("; $this->propertyPreg .= "([\$]{$attributes['item']}[@](";
$properties = $this->itemProperties; $properties = $this->itemProperties;
} }
@@ -130,6 +151,16 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
$this->propertyPreg .= '))'; $this->propertyPreg .= '))';
} }
/**
* Find matches in template source
*
* @param \Smarty_Internal_TemplateCompiler $compiler
*/
public function matchTemplateSource(Smarty_Internal_TemplateCompiler $compiler)
{
$this->matchProperty($compiler->parser->lex->data);
}
/** /**
* Find matches in source string * Find matches in source string
* *
@@ -140,81 +171,10 @@ class Smarty_Internal_Compile_Private_ForeachSection extends Smarty_Internal_Com
preg_match_all($this->propertyPreg, $source, $match, PREG_SET_ORDER); preg_match_all($this->propertyPreg, $source, $match, PREG_SET_ORDER);
foreach ($this->resultOffsets as $key => $offset) { foreach ($this->resultOffsets as $key => $offset) {
foreach ($match as $m) { foreach ($match as $m) {
if (isset($m[$offset]) && !empty($m[$offset])) { if (isset($m[ $offset ]) && !empty($m[ $offset ])) {
$this->matchResults[$key][strtolower($m[$offset])] = true; $this->matchResults[ $key ][ strtolower($m[ $offset ]) ] = true;
} }
} }
} }
} }
/**
* Find matches in template source
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
*/
public function matchTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler)
{
$this->matchProperty($compiler->parser->lex->data);
}
/**
* Find matches in all parent template source
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
*/
public function matchParentTemplateSource(Smarty_Internal_TemplateCompilerBase $compiler)
{
// search parent compiler template source
$nextCompiler = $compiler;
while ($nextCompiler !== $nextCompiler->parent_compiler) {
$nextCompiler = $nextCompiler->parent_compiler;
if ($compiler !== $nextCompiler) {
// get template source
$_content = $nextCompiler->template->source->getContent();
if ($_content != '') {
// run pre filter if required
if ((isset($nextCompiler->smarty->autoload_filters['pre']) ||
isset($nextCompiler->smarty->registered_filters['pre']))) {
$_content = $nextCompiler->smarty->ext->_filterHandler->runFilter('pre', $_content, $nextCompiler->template);
}
$this->matchProperty($_content);
}
}
}
}
/**
* Find matches in {block} tag source
*
* @param \Smarty_Internal_TemplateCompilerBase $compiler
*/
public function matchBlockSource(Smarty_Internal_TemplateCompilerBase $compiler)
{
}
/**
* Compiles code for the {$smarty.foreach.xxx} or {$smarty.section.xxx}tag
*
* @param array $args array with attributes from parser
* @param \Smarty_Internal_TemplateCompilerBase $compiler compiler object
* @param array $parameter array with compilation parameter
*
* @return string compiled code
* @throws \SmartyCompilerException
*/
public function compileSpecialVariable($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
$tag = strtolower(trim($parameter[ 0 ], '"\''));
$name = isset($parameter[ 1 ]) ? $compiler->getId($parameter[ 1 ]) : false;
if (!$name) {
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} name attribute", null, true);
}
$property = isset($parameter[ 2 ]) ? strtolower($compiler->getId($parameter[ 2 ])) : false;
if (!$property || !in_array($property, $this->nameProperties)) {
$compiler->trigger_template_error("missing or illegal \$smarty.{$tag} property attribute", null, true);
}
$tagVar = "'__smarty_{$tag}_{$name}'";
return "(isset(\$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}']) ? \$_smarty_tpl->tpl_vars[{$tagVar}]->value['{$property}'] : null)";
}
} }