blob: 52e0a96f2a3d6a45bf9c3a7111cb2c86a5154d24 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
<?php
/*
* This file is part of Twig.
*
* (c) 2009 Fabien Potencier
* (c) 2009 Armin Ronacher
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Represents a for node.
*
* @package twig
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class phpbb_template_twig_node_begin extends Twig_Node
{
public function __construct($beginName, Twig_NodeInterface $body, Twig_NodeInterface $else = null, $lineno, $tag = null)
{
parent::__construct(array('body' => $body, 'else' => $else), array('beginName' => $beginName), $lineno, $tag);
}
/**
* Compiles the node to PHP.
*
* @param Twig_Compiler A Twig_Compiler instance
*/
public function compile(Twig_Compiler $compiler)
{
$compiler
->write("if (!isset(\$loops)) {\n")
->indent()
->write("\$loops = array();")
->write("\$nestingLevel = 0;")
->outdent()
->write("}\n")
->write("\$loops[\$nestingLevel] = array();\n")
;
if (null !== $this->getNode('else')) {
$compiler->write("\$loops[\$nestingLevel]['iterated'] = false;\n");
}
$compiler
->write("if (isset(\$context['loop'])) {")
->write("foreach (\$context['loop']['")
->write($this->getAttribute('beginName'))
->write("'] as \$loops[\$nestingLevel]['i'] => \$loops[\$nestingLevel]['values']) {")
->indent()
;
$compiler->subcompile($this->getNode('body'));
if (null !== $this->getNode('else')) {
$compiler->write("\$loops[\$nestingLevel]['iterated'] = true;\n");
}
$compiler
->outdent()
->write("}}\n")
;
if (null !== $this->getNode('else')) {
$compiler
->write("if (!\$loops[\$nestingLevel]['iterated']) {\n")
->indent()
->subcompile($this->getNode('else'))
->outdent()
->write("}\n")
;
}
$compiler->write("\$nestingLevel--;\n");
}
}
|