Update Twig. This closes #295

This commit is contained in:
Fredrick Brennan
2018-05-10 18:24:53 +08:00
parent b078ffb1e4
commit 0aa4e3badc
200 changed files with 6150 additions and 2626 deletions

View File

@@ -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);