summaryrefslogtreecommitdiff
path: root/inc/lib/Twig/Node/For.php
diff options
context:
space:
mode:
authorBenjamin Southall <applemansigloo@gmail.com>2019-02-26 10:11:12 +1000
committerBenjamin Southall <applemansigloo@gmail.com>2019-02-26 10:11:12 +1000
commitf79395851b044689567e0e6c9504acbcaa742782 (patch)
treeee539aee9ffa90e8accd6f130b30a8ebed7a232e /inc/lib/Twig/Node/For.php
parent28f32baf0125ca5085266e73dc5071e5814d8e3b (diff)
Twig update to latest Twig 1.x legacy as per vichan
Diffstat (limited to 'inc/lib/Twig/Node/For.php')
-rw-r--r--inc/lib/Twig/Node/For.php29
1 files changed, 15 insertions, 14 deletions
diff --git a/inc/lib/Twig/Node/For.php b/inc/lib/Twig/Node/For.php
index d1ff371d..914b70c9 100644
--- a/inc/lib/Twig/Node/For.php
+++ b/inc/lib/Twig/Node/For.php
@@ -3,8 +3,8 @@
/*
* This file is part of Twig.
*
- * (c) 2009 Fabien Potencier
- * (c) 2009 Armin Ronacher
+ * (c) Fabien Potencier
+ * (c) Armin Ronacher
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
@@ -27,26 +27,25 @@ class Twig_Node_For extends Twig_Node
$body = new Twig_Node_If(new Twig_Node(array($ifexpr, $body)), null, $lineno, $tag);
}
- parent::__construct(array('key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body, 'else' => $else), array('with_loop' => true, 'ifexpr' => null !== $ifexpr), $lineno, $tag);
+ $nodes = array('key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body);
+ if (null !== $else) {
+ $nodes['else'] = $else;
+ }
+
+ parent::__construct($nodes, array('with_loop' => true, 'ifexpr' => null !== $ifexpr), $lineno, $tag);
}
- /**
- * Compiles the node to PHP.
- *
- * @param Twig_Compiler A Twig_Compiler instance
- */
public function compile(Twig_Compiler $compiler)
{
$compiler
->addDebugInfo($this)
- // the (array) cast bypasses a PHP 5.2.6 bug
- ->write("\$context['_parent'] = (array) \$context;\n")
+ ->write("\$context['_parent'] = \$context;\n")
->write("\$context['_seq'] = twig_ensure_traversable(")
->subcompile($this->getNode('seq'))
->raw(");\n")
;
- if (null !== $this->getNode('else')) {
+ if ($this->hasNode('else')) {
$compiler->write("\$context['_iterated'] = false;\n");
}
@@ -75,14 +74,14 @@ class Twig_Node_For extends Twig_Node
}
}
- $this->loop->setAttribute('else', null !== $this->getNode('else'));
+ $this->loop->setAttribute('else', $this->hasNode('else'));
$this->loop->setAttribute('with_loop', $this->getAttribute('with_loop'));
$this->loop->setAttribute('ifexpr', $this->getAttribute('ifexpr'));
$compiler
->write("foreach (\$context['_seq'] as ")
->subcompile($this->getNode('key_target'))
- ->raw(" => ")
+ ->raw(' => ')
->subcompile($this->getNode('value_target'))
->raw(") {\n")
->indent()
@@ -91,7 +90,7 @@ class Twig_Node_For extends Twig_Node
->write("}\n")
;
- if (null !== $this->getNode('else')) {
+ if ($this->hasNode('else')) {
$compiler
->write("if (!\$context['_iterated']) {\n")
->indent()
@@ -110,3 +109,5 @@ class Twig_Node_For extends Twig_Node
$compiler->write("\$context = array_intersect_key(\$context, \$_parent) + \$_parent;\n");
}
}
+
+class_alias('Twig_Node_For', 'Twig\Node\ForNode', false);