Merge branch '1.x' into 2.x

* 1.x:
  tweaked twig_to_array
This commit is contained in:
Fabien Potencier
2019-04-11 08:51:43 +02:00
2 changed files with 13 additions and 13 deletions
+2 -6
View File
@@ -40,18 +40,14 @@ class WithNode extends Node
->write(sprintf('$%s = ', $varsName))
->subcompile($this->getNode('variables'))
->raw(";\n")
->write(sprintf("if (\$%s instanceof \\Traversable) {\n", $varsName))
->indent()
->write(sprintf("\$%s = iterator_to_array(\$%s);\n", $varsName, $varsName))
->outdent()
->write("}\n")
->write(sprintf("if (!is_array(\$%s)) {\n", $varsName))
->write(sprintf("if (!twig_test_iterable(\$%s)) {\n", $varsName))
->indent()
->write("throw new RuntimeError('Variables passed to the \"with\" tag must be a hash.', ")
->repr($this->getTemplateLine())
->raw(", \$this->source);\n")
->outdent()
->write("}\n")
->write(sprintf("\$%s = twig_to_array(\$%s);\n", $varsName, $varsName))
;
if ($this->getAttribute('only')) {