Merge pull request #2391 from naderman/ticket/12382

[ticket/12382] Allow nested loops in included files.
This commit is contained in:
Joas Schilling 2014-05-03 00:21:50 +02:00
commit a995f1166c
5 changed files with 15 additions and 10 deletions

View file

@ -191,9 +191,16 @@ class lexer extends \Twig_Lexer
$parent_class = $this; $parent_class = $this;
$callback = function ($matches) use ($parent_class, $parent_nodes) $callback = function ($matches) use ($parent_class, $parent_nodes)
{ {
$name = $matches[1]; $hard_parents = explode('.', $matches[1]);
$subset = trim(substr($matches[2], 1, -1)); // Remove parenthesis array_pop($hard_parents); // ends with .
$body = $matches[3]; if ($hard_parents)
{
$parent_nodes = array_merge($hard_parents, $parent_nodes);
}
$name = $matches[2];
$subset = trim(substr($matches[3], 1, -1)); // Remove parenthesis
$body = $matches[4];
// Replace <!-- BEGINELSE --> // Replace <!-- BEGINELSE -->
$body = str_replace('<!-- BEGINELSE -->', '{% else %}', $body); $body = str_replace('<!-- BEGINELSE -->', '{% else %}', $body);
@ -242,7 +249,7 @@ class lexer extends \Twig_Lexer
return "{% for {$name} in {$parent}{$name}{$subset} %}{$body}{% endfor %}"; return "{% for {$name} in {$parent}{$name}{$subset} %}{$body}{% endfor %}";
}; };
return preg_replace_callback('#<!-- BEGIN ([!a-zA-Z0-9_]+)(\([0-9,\-]+\))? -->(.+?)<!-- END \1 -->#s', $callback, $code); return preg_replace_callback('#<!-- BEGIN ((?:[a-zA-Z0-9_]+\.)*)([!a-zA-Z0-9_]+)(\([0-9,\-]+\))? -->(.+?)<!-- END \1\2 -->#s', $callback, $code);
} }
/** /**

View file

@ -1,2 +1,2 @@
[{event_loop.S_ROW_COUNT}<!-- BEGIN subloop -->[subloop:{event_loop.subloop.S_ROW_COUNT}] [{event_loop.S_ROW_COUNT}<!-- BEGIN event_loop.subloop -->[subloop:{event_loop.subloop.S_ROW_COUNT}]
<!-- END subloop -->] <!-- END event_loop.subloop -->]

View file

@ -102,7 +102,6 @@ Zeta test event in all',
), ),
array(), array(),
'event_loop[0[subloop:0]]', 'event_loop[0[subloop:0]]',
'Event files are missing opened parent loops: PHPBB3-12382',
), ),
); );
} }

View file

@ -330,7 +330,6 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
array(), array(),
"[bar|[bar|]][bar1|[bar1|[bar1|works]]]", "[bar|[bar|]][bar1|[bar1|[bar1|works]]]",
array(), array(),
'Included files are missing opened parent loops: PHPBB3-12382',
), ),
/* Does not pass with the current implementation. /* Does not pass with the current implementation.
array( array(

View file

@ -1,5 +1,5 @@
[{test_loop.foo}| [{test_loop.foo}|
<!-- BEGIN inner --> <!-- BEGIN test_loop.inner -->
[{test_loop.foo}| [{test_loop.foo}|
{test_loop.inner.myinner}] {test_loop.inner.myinner}]
<!-- END inner -->] <!-- END test_loop.inner -->]