mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 20:36:33 +00:00
Fix the For optimizer, "include" function was always optimized
This commit is contained in:
@@ -205,6 +205,16 @@ class Twig_NodeVisitor_Optimizer implements Twig_NodeVisitorInterface
|
|||||||
$this->addLoopToAll();
|
$this->addLoopToAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// include function without the with_context=false parameter
|
||||||
|
elseif ($node instanceof Twig_Node_Expression_Function
|
||||||
|
&& 'include' === $node->getAttribute('name')
|
||||||
|
&& (!$node->getNode('arguments')->hasNode('with_context')
|
||||||
|
|| false !== $node->getNode('arguments')->getNode('with_context')->getAttribute('value')
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
$this->addLoopToAll();
|
||||||
|
}
|
||||||
|
|
||||||
// the loop variable is referenced via an attribute
|
// the loop variable is referenced via an attribute
|
||||||
elseif ($node instanceof Twig_Node_Expression_GetAttr
|
elseif ($node instanceof Twig_Node_Expression_GetAttr
|
||||||
&& (!$node->getNode('attribute') instanceof Twig_Node_Expression_Constant
|
&& (!$node->getNode('attribute') instanceof Twig_Node_Expression_Constant
|
||||||
|
|||||||
@@ -89,6 +89,16 @@ class Twig_Tests_NodeVisitor_OptimizerTest extends PHPUnit_Framework_TestCase
|
|||||||
array('{% for i in foo %}{% for j in foo %}{{ foo.parent.loop.index }}{% endfor %}{% endfor %}', array('i' => false, 'j' => false)),
|
array('{% for i in foo %}{% for j in foo %}{{ foo.parent.loop.index }}{% endfor %}{% endfor %}', array('i' => false, 'j' => false)),
|
||||||
|
|
||||||
array('{% for i in foo %}{% for j in foo %}{{ loop["parent"].loop.index }}{% endfor %}{% endfor %}', array('i' => true, 'j' => true)),
|
array('{% for i in foo %}{% for j in foo %}{{ loop["parent"].loop.index }}{% endfor %}{% endfor %}', array('i' => true, 'j' => true)),
|
||||||
|
|
||||||
|
array('{% for i in foo %}{{ include("foo") }}{% endfor %}', array('i' => true)),
|
||||||
|
|
||||||
|
array('{% for i in foo %}{{ include("foo", with_context = false) }}{% endfor %}', array('i' => false)),
|
||||||
|
|
||||||
|
array('{% for i in foo %}{{ include("foo", with_context = true) }}{% endfor %}', array('i' => true)),
|
||||||
|
|
||||||
|
array('{% for i in foo %}{{ include("foo", { "foo": "bar" }, with_context = false) }}{% endfor %}', array('i' => false)),
|
||||||
|
|
||||||
|
array('{% for i in foo %}{{ include("foo", { "foo": loop.index }, with_context = false) }}{% endfor %}', array('i' => true)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user