From: Fabien Potencier Date: Thu, 27 May 2010 16:42:40 +0000 (+0200) Subject: fixed iterator_to_array() usage (closes #57) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=92ae9ac85437e203ca7e69c51c5910301a2f79fd;p=web%2Fkonrad%2Ftwig.git fixed iterator_to_array() usage (closes #57) --- diff --git a/CHANGELOG b/CHANGELOG index 225ca4e..d5adc45 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index be92d94..241614e 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -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(); } diff --git a/lib/Twig/Node/For.php b/lib/Twig/Node/For.php index f7541ce..761de92 100644 --- a/lib/Twig/Node/For.php +++ b/lib/Twig/Node/For.php @@ -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) {