fixed iterator_to_array() usage (closes #57)

This commit is contained in:
Fabien Potencier
2010-05-27 18:42:40 +02:00
parent 1847634d0c
commit 92ae9ac854
3 changed files with 5 additions and 4 deletions
+1
View File
@@ -3,6 +3,7 @@
Backward incompatibilities:
* The short notation of the `block` tag changed.
* fixed iterator_to_array() usage
* changed the date filter to support any date format supported by DateTime
* added ignore_invalid_variables setting to throw an exception when an invalid variable is used in a template (disabled automatically when debug is true)
* added the lexer, parser, and compiler as arguments to the Twig_Environment constructor
+3 -3
View File
@@ -185,7 +185,7 @@ function twig_in_filter($value, $compare)
} elseif (is_string($compare)) {
return false !== strpos($compare, (string) $value);
} elseif (is_object($compare) && $compare instanceof Traversable) {
return in_array($value, iterator_to_array($compare));
return in_array($value, iterator_to_array($compare, false));
}
return false;
@@ -298,12 +298,12 @@ else
}
}
function twig_iterator_to_array($seq)
function twig_iterator_to_array($seq, $useKeys = true)
{
if (is_array($seq)) {
return $seq;
} elseif (is_object($seq) && $seq instanceof Traversable) {
return $seq instanceof Countable ? $seq : iterator_to_array($seq);
return $seq instanceof Countable ? $seq : iterator_to_array($seq, $useKeys);
} else {
return array();
}
+1 -1
View File
@@ -69,7 +69,7 @@ class Twig_Node_For extends Twig_Node implements Twig_NodeListInterface
$compiler
->write("\$context['_seq'] = twig_iterator_to_array(")
->subcompile($this->seq)
->raw(");\n")
->raw(", ".($this->isMultitarget ? 'true' : 'false').");\n")
;
if ($this->withLoop) {